message: chore: enable search bar
diff: @@ -18,6 +18,8 @@ const readDir = inputDir =>
  const isHtmlFile = fileName => fileName.endsWith('.html');
  +const isSearchJs = fileName => fileName.endsWith('search.js');
  +
  const pipe = (...fns) => start => fns.reduce((state, fn) => fn(state), start);
  /*
  @@ -28,36 +30,37 @@ https://username.github.io/repo/modules/_sap_cloud_sdk_analytics not
  https://username.github.io/repo/modules/_sap_cloud_sdk_analytics.html not
  */
  function adjustmentForGitHubPages() {
  - const paths = flatten(readDir('./documentation')).filter(isHtmlFile);
  - paths.forEach(path => replaceSearchbar(path));
  - paths.forEach(path => replaceUnderlinePrefixAndHtmlSuffixFromLinks(path));
  - paths.forEach(path => removeUnderlinePrefixFromFileName(path));
  -
  + const documentationFiles = flatten(readDir('./documentation'));
  + const htmlPaths = documentationFiles.filter(isHtmlFile);
  + adjustSearchJs(documentationFiles);
  + htmlPaths.forEach(path => replaceUnderlinePrefixAndHtmlSuffixFromLinks(path));
  + htmlPaths.forEach(path => removeUnderlinePrefixFromFileName(path));
  }
  -function replaceSearchbar(path) {
  - const labelEl = '<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>';
  - const inputEl = '<input id="tsd-search-field" type="text" />';
  +function adjustSearchJs(paths){
  + const filtered = paths.filter(isSearchJs);
  + if(filtered.length !== 1){
  + throw Error(`Expect one 'search.js', but found: ${filtered.length}.`);
  + }
  + replaceUnderlinePrefixAndHtmlSuffixFromSearchJs(filtered[0]);
  +}
  +function replaceUnderlinePrefixAndHtmlSuffixFromSearchJs(path){
  const html = fs.readFileSync(path, { encoding: 'utf8' });
  - if (html.includes(labelEl) && html.includes(inputEl)) {
  - const replaced = html.replace(labelEl, '').replace(inputEl, '');
  + const replaced = html.replace(/"[^"]*_[^"]*.html[^"]*"/gi, removeUnderlinePrefixAndHtmlSuffix);
  fs.writeFileSync(path, replaced, { encoding: 'utf8' });
  - } else {
  - throw Error('Searchbar could not be hidden. Label and input tags are not defined.');
  - }
  }
  function replaceUnderlinePrefixAndHtmlSuffixFromLinks(path){
  const html = fs.readFileSync(path, { encoding: 'utf8' });
  - const replaced = html.replace(/<a href="[^>]*_[^>]*.html[^>]*>/gi, removeUnderlinePrefixAndHtmlSuffixFromLink);
  + const replaced = html.replace(/<a href="[^>]*_[^>]*.html[^>]*>/gi, removeUnderlinePrefixAndHtmlSuffix);
  fs.writeFileSync(path, replaced, { encoding: 'utf8' });
  }
  -function removeUnderlinePrefixAndHtmlSuffixFromLink(aHref) {
  - const i = aHref.indexOf('_');
  +function removeUnderlinePrefixAndHtmlSuffix(str) {
  + const i = str.indexOf('_');
  // remove the first `_`
  - const firstUnderlineRemoved = aHref.substring(0, i) + aHref.substring(i + 1);
  + const firstUnderlineRemoved = str.substring(0, i) + str.substring(i + 1);
  // remove `.html`
  return firstUnderlineRemoved.replace('.html', '');
  }
  