elegant
elegant copied to clipboard
[Help] Is there an easy way to include custom code in all elegant created files?
Mandatory Step
- [x] I am using latest production release of Elegant
Recommended Step
- [ ] I have attached link to my blog source code repository
- [ ] I have reproduced my pelican configuration files
I need help with
Describe your question
I want to add a script section on my generated page, but I want still to use untouched elegant theme.
Is there a way so that we can define custom scripts that gets added to each page without having to mantain a custom base.html file?
Thanks Pablo
That's a very good question. I too have been thinking about it recently. I want to customize CSS for the site title in the top menu bar.
The possible solution I have in mind is to define two variables in the pelicanconf.py
.
CUSTOM_CSS = "../blah/my_styles.css"
CUSTOM_JS_BASE = "../blah/my_script.js"
Then if these variables are defined we import them
- into our templates
- assets template (so that they are minified by the assets plugin
But I haven't tested this idea.
I was thinking about:
- custom head
- custom footer
- custom body
With those defined in variable, and pointing to an existing file, source that file as a jinja template so that you can 'render' more complex files.
Even 'pre' code could copy from file location to template file inside templates for easier inclusion, etc (if needed)
If a user wants custom head, footer and body then he probably needs some other theme. Customization is good but at some point you reach the point where creating a new theme or forking an existing theme is much feasible.
Yes, for some point yes, but for a 'stats' scripts we don't support you want on headers, let's say for example adobe analytics, or if you want a custom footer like 'powered by $random on realtech' or even custom body for some 'law' regulatory messaging
At some point you might need something else, but for most cases it should just allow to insert custom jinja template and be enough.
My actual use case when thought about it is just a new JS in headers
but for a 'stats' scripts we don't support you want on headers
A PR solves this issue. Heap analytics support was added via PR by someone else.
you want a custom footer like 'powered by $random on realtech
We shouldn't encourage it. Because we want to people to know about Elegant and Pelican. They can remove it via fork though.
In the first license I didn't allow it even in the fork but when we moved to bazar model, I removed this restriction from the license.
My actual use case when thought about it is just a new JS in headers
We are not against accepting any PRs. If a user wants adobe analytics support on top of latest Elegant releases, he can always open PR. Same for all other use cases.
You add ways to customize by injecting Jinja templates, it will result in
- Complicated code
- Difficult to support issues
- Less contributions to the upstream
https://github.com/Pelican-Elegant/elegant/pull/439 is related with this, but using the 'add new feature' approach
Another option to explore is CSS_FILE
option in Pelican configuration.
https://docs.getpelican.com/en/stable/settings.html?highlight=css_file#themes
Not sure how it works. But it may enable us to to let user add custom CSS.