-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix current page detection for clean URLs #2993
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,9 @@ impl HtmlHandlebars { | |
| ctx.data.insert("title".to_owned(), json!(title)); | ||
| ctx.data | ||
| .insert("path_to_root".to_owned(), json!(fs::path_to_root(path))); | ||
| let current_link = path.with_extension("html").to_url_path(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm noticing that I don't think it matters too much because there is no sidebar navigation for the print page. Offhand I don't think it is required, but I do have a little unease about having a missing variable. |
||
| ctx.data | ||
| .insert("current_link".to_owned(), json!(current_link)); | ||
| if let Some(ref section) = ch.number { | ||
| ctx.data | ||
| .insert("section".to_owned(), json!(section.to_string())); | ||
|
|
@@ -127,6 +130,8 @@ impl HtmlHandlebars { | |
| ctx.data.insert("path".to_owned(), json!("index.md")); | ||
| ctx.data.insert("path_to_root".to_owned(), json!("")); | ||
| ctx.data.insert("is_index".to_owned(), json!(true)); | ||
| ctx.data | ||
| .insert("current_link".to_owned(), json!("index.html")); | ||
| let rendered_index = ctx.handlebars.render("index", &ctx.data)?; | ||
| debug!("Creating index.html from {}", ctx_path); | ||
| fs::write(ctx.destination.join("index.html"), rendered_index)?; | ||
|
|
@@ -180,6 +185,7 @@ impl HtmlHandlebars { | |
| // Set a dummy path to ensure other paths (e.g. in the TOC) are generated correctly | ||
| data_404.insert("path".to_owned(), json!("404.md")); | ||
| data_404.insert("content".to_owned(), json!(html_content_404)); | ||
| data_404.insert("current_link".to_owned(), json!("404.html")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing to change here. Just noting that this isn't technically correct because the output filename can be customized. However, since there isn't anything in the sidebar for it to match, I don't think it matters. |
||
|
|
||
| let mut title = String::from("Page not found"); | ||
| if let Some(book_title) = &ctx.config.book.title { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this would be a breaking change if the user has a custom
index.hbs. I try to be a little cautious about making those kinds of changes.View changes since the review