Closed sypets closed 6 years ago
Sounds good.
Thanks for the thoughts and the PR. Actually, it isn't that easy. Because ...
I will close this one to remove it from the list of pull request. Instead, I will handle this as an issue.
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, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').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>'
));
Resolves: #84
before
after
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