Skip to content
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

fix(theme): Fix side menu being stuck open and obscuring most of the … #376

Merged
merged 1 commit into from
Oct 4, 2023
Merged
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
7 changes: 6 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ site-url = "/patterns/"
git-repository-url = "https://github.com/rust-unofficial/patterns"
git-repository-icon = "fa-github"
edit-url-template = "https://github.com/rust-unofficial/patterns/edit/main/{path}"
additional-css = ["./language-picker.css"]
additional-css = ["theme/css/language-picker.css"]

[output.html.fold]
enable = true
Expand All @@ -33,3 +33,8 @@ level = 1
editable = false

# [output.linkcheck] # enable the "mdbook-linkcheck" renderer, disabled due to gh-actions

[output.html.redirect]
# Redirects in the form of "old-path" = "new-path", where the new path
# is relative to the old path.
"functional/lenses.html" = "optics.html"
5 changes: 5 additions & 0 deletions language-picker.css → theme/css/language-picker.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
right: 10px;
}

[dir="rtl"] #language-list {
left: 10px;
right: auto;
}

#language-list a {
color: inherit;
}
26 changes: 26 additions & 0 deletions theme/head.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{! Move to template code after fixing this issue:
https://github.com/google/mdbook-i18n-helpers/issues/70 }}
<script>
(function () {
// See these pages for details:
// https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls
// https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics
let base = "https://rust-unofficial.github.io/patterns";
{{#if(eq language "en")}}
let canonical_href = `${base}/{{ path }}`;
{{else}}
let canonical_href = `${base}/{{ language }}/{{ path }}`;
{{/if}}

// mdbook gives us a string ending in ".md", we replace it with ".html":
canonical_href = canonical_href.slice(0, -"md".length) + "html";
if (canonical_href.endsWith("/index.html")) {
canonical_href = canonical_href.slice(0, -"index.html".length);
}

let link = document.createElement("link");
link.rel = "canonical";
link.href = canonical_href;
document.head.appendChild(link);
}) ()
</script>
Loading
Loading