-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Adding a header partial integration #453 #454
Conversation
handlebars.register_template_string( | ||
"index", | ||
String::from_utf8(theme.index.clone())?, | ||
)?; | ||
|
||
debug!("[*]: Register the header handlebars template"); | ||
handlebars.register_template_string( |
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.
As far as I understand the register_partial
would be contextually more appropriate (yes currently these two functions have identical implementation but this can change in the future)
src/book/mod.rs
Outdated
@@ -262,6 +262,10 @@ impl MDBook { | |||
let mut index = File::create(&themedir.join("index.hbs"))?; | |||
index.write_all(theme::INDEX)?; | |||
|
|||
// header.hbs | |||
let mut header = File::create(&themedir.join("header.hbs"))?; |
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.
and when the "header.hbs" is missing?
I understand that this should be handled similarly to "additional.css/js". Hmm We might be interested in extracting some type hbs partials registry.
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.
So this works similar to other /present/ files in the theme, in that there's already a blank header.hbs
file and when the user doesn't supply one, the blank one is used, so it does nothing. I don't think I'm clear on what the difference is.
If we want to be more free form we could just let the user specify partials and then they can override the index.hbs
itself to use their own partials in their own places (maybe this is one way to address CSS problems).
Thanks @projektir ! I think that we might be interested in generalizing the implementation a little and possibly extraction of some hbs blocks from index.hbs to separate files. But we would need to wait on word from @azerupi if he is interested in such feature at all (I know I am :)). |
I believe @azerupi marked this as |
Yes, I fully support splitting the index.hbs file into multiple parts that can be overridden independently. We can start with just this and add more partials in a more iterative fashion. :)
What is the problem with additional classes / css? |
@azerupi Here's the relevant commit: rust-lang/book@bcb1cc5#diff-ebf1c3b21d73d0e04f32752d0b51ad38 |
Ok, but what problem does that cause exactly? Is it the fact that they overwrite the index.hbs file to add a class? If that is the problem they can just add custom css rules to the If that is not the problem I need more clarifications to understand. |
It means they still need to override the I'm not sure why you're reacting like that. If you think there's no problem that's a good thing, but I don't don't necessarily know your view nor do I have the full picture of what mdBook does, so I don't think it's unreasonable for me to want make sure that the original issue is indeed addressed. Additional CSS and JS can be used to add a header even without a partial, also, but this is not what happened, so potentially there's a barrier to using those. But, yes, it can be done. |
For TRPL, since there's other changes to For The Reference, we can remove the class, and just add the CSS to the page no matter what - leaving a comment in both the header.hbs and whichever CSS file saying what they are for. The CSS we use is: .page-wrapper.has-warning > .nav-chapters {
/* add height for warning content & margin */
top: 120px;
} So if the .nav-chapters could be below whatever content is in |
Oh, I didn't know that. Yeah that makes sense then. I'm not sure if I'm quite following the thing with the reference but I guess that's mostly going to be figured out on that side. If someone wants me to add the other parts to be partials let me know, otherwise we can perhaps close this? |
I'm sorry, I think we misunderstood each other. I truly did not understand what the problem was and I want to understand the issue before suggesting any solution. Now that I better understand the problem, I can try to find the best possible solution. I thought that the problem you were talking about was simply adding some new classes to elements and give them a style. So I was trying to propose an alternate solution for the commit you linked to. Now I see that you want the underlying problem to be solved, namely to not have to override the included .hbs files for simple changes. I think it is a problem worth solving, so I am going to think about this. An idea for exploration: It should be possible to extend templates and include the original inside the extended template. At least in other templating languages it is possible if I remember correctly. This would allow users to extend the templates without overwriting them. |
@azerupi so that sounds like a separate effort. Can we merge this PR for now and close the issue about the header and open a different one, perhaps? |
@projektir, other than doing a |
Whoops, sorry, didn't notice this update. I'll rebase this up in a day or two. |
I rebased it, but I'm having trouble replacing the header now... not sure if I am doing something wrong or something else changed with theme replacement... |
@Michael-F-Bryan |
LGTM 👍 It seems like all mac jobs for travis are blocked indefinitely, but that's most probably just Travis struggling with availability. I'm going to merge this. |
Adding a header partial integration rust-lang#453
Addresses #453.
Giving this an initial stab.
I've tested it and it works: you need to point the theme at the location of your theme folder with the modified
header.hbs
, otherwise the default one is blank.This still doesn't address the problem of additional classes/CSS, though...
Let me know what you think!