TYPO3-Documentation / t3SphinxThemeRtd

Please report only issues that concern the rendering of the official TYPO3 docs here. For help and support on TYPO3, please see: https://typo3.org/help/
MIT License
11 stars 7 forks source link

[FEATURE] Add additional help and links to search results page #87

Closed sypets closed 6 years ago

sypets commented 6 years ago

Resolves: #84

before

before

after

after2

This will automatically generate the URL for the search engine startpage.com, restricting it to docs.typo3.org and using the search terms the user entered.

This is the URL used in the screenshot:

https://www.startpage.com/do/dsearch?query=site%3Adocs.typo3.org+suggestwizard

It will also properly encode search terms. Will also work with more than one term:

https://www.startpage.com/do/dsearch?query=site%3Adocs.typo3.org+suggest+wizard

marble commented 6 years ago

Sounds good.

marble commented 6 years ago

Thanks for the thoughts and the PR. Actually, it isn't that easy. Because ...

marble commented 6 years ago

I will close this one to remove it from the list of pull request. Instead, I will handle this as an issue.

sypets commented 5 years ago

Since PR is closed, I am adding code snippet here, so work is not lost (if branch gets deleted):

static/searchtools.js:

 /**
   * sanitize input for html
   *
   * Here, we don't correctly convert html entities.
   * We just make sure it's all converted to harmless +     *
   *
   * escape: &, <, >, ", ', `, , !, @, $, %, (, ), =, +, {, }, [, and ]
   *
   * see https://wonko.com/post/html-escaping
   * @param s input string
   * @returns string
   */
  encodeHtml :  function(s) {
      s = s.replace(/;/g, '+').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/ /g, '+');
      return s.replace(/[<>'"`!@$%()=+{}[]+/g, '+');
  },
 var searchResultText = '';

        if (!resultCount) {
            searchResultText = 'Your search did not match any documents. Please make sure that all words are spelled correctly.';
        } else {
            searchResultText = 'Search finished, found ' + resultCount + ' page(s) matching the search query.';
        }

        // Add additional information and link to external search engines
        var docTitleElement = $("div.wy-side-nav-search ul.sidebartop li.project [href]");
        var docTitle = '';
        if (docTitleElement != null) {
            docTitle = docTitleElement.text();
        }
        var encodedQuery = Search.encodeHtml(query);
        var searchUrl1 = 'https://www.startpage.com/do/dsearch?query=site%3Adocs.typo3.org+' + encodeURI(encodedQuery);
        Search.status.html(_( searchResultText
            + '<hr /><em>The search function only searches within the current manual ' + docTitle + '.</em>'
            + '<br/> For a wider search, try: '
            + '<a href="' + searchUrl1 + '">startpage.com with site:docs.typo3.org ' + encodedQuery + '</a>'
        ));