elegant icon indicating copy to clipboard operation
elegant copied to clipboard

[Help] Is there an easy way to include custom code in all elegant created files?

Open iranzo opened this issue 5 years ago • 8 comments

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

iranzo avatar Jul 11 '19 14:07 iranzo

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

  1. into our templates
  2. assets template (so that they are minified by the assets plugin

But I haven't tested this idea.

talha131 avatar Jul 11 '19 16:07 talha131

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)

iranzo avatar Jul 11 '19 17:07 iranzo

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.

talha131 avatar Jul 11 '19 17:07 talha131

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

iranzo avatar Jul 11 '19 17:07 iranzo

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

  1. Complicated code
  2. Difficult to support issues
  3. Less contributions to the upstream

talha131 avatar Jul 11 '19 18:07 talha131

https://github.com/Pelican-Elegant/elegant/pull/439 is related with this, but using the 'add new feature' approach

iranzo avatar Jul 12 '19 14:07 iranzo

What needs to be done here

  1. See this comment
  2. Implement it
  3. Test it
  4. Open PR for it

talha131 avatar Jul 14 '19 16:07 talha131

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.

talha131 avatar Aug 21 '19 19:08 talha131