Skip to content

use mkdocs builtin search.html #2289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion readthedocs/core/static-src/core/js/doc-embed/mkdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ function init() {
value: 'file'
}).appendTo('#rtd-search-form');

$("#rtd-search-form").prop("action", rtd.api_host + "/search/");
var search_url = window.location.protocol + "//" + window.location.hostname +
"/" + rtd.language + "/" + rtd.version + "/search.html";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't respect subprojects and aliases. We can't assume the project path is https://hostname/language/version/search.html, it could be https://hostname/projects/subproject/language/version/search.html. Same for aliases here.

$("#rtd-search-form").prop("action", search_url);

// Apply stickynav to mkdocs builds
var nav_bar = $('nav.wy-nav-side:first'),
Expand Down
9 changes: 7 additions & 2 deletions readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ def append_conf(self, **kwargs):
data_file = open(os.path.join(self.root_path, docs_dir, 'readthedocs-data.js'), 'w+')
data_file.write(data_string)
data_file.write('''
READTHEDOCS_DATA["page"] = mkdocs_page_input_path.substr(
0, mkdocs_page_input_path.lastIndexOf(READTHEDOCS_DATA.source_suffix));
//mkdocs doesn't expose this var for non-content-bearing pages (such as search.html)
if(typeof mkdocs_page_input_path !== "undefined")
{
READTHEDOCS_DATA["page"] = mkdocs_page_input_path.substr(
0, mkdocs_page_input_path.lastIndexOf(READTHEDOCS_DATA.source_suffix));
}
//else, ["page"] will be null
''')
data_file.close()

Expand Down