Add CSS rules to Pelican without creating a theme
Asked Answered
A

2

5

I rather like the default Pelican theme notmyidea. It serves my purposes nicely.

However, in order to implement the Python-Markdown admonishments extension, I need to add a few css rules to the template.

Nothing I can find in the documentation (or through googling) seems to explain how to do this. Only how to create a brand new theme, or use a custom style sheet, which overrides the default style sheet.

Is there a way to add a supplementary style sheet or even just a few supplementary rules?

Anschluss answered 4/1, 2019 at 21:19 Comment(5)
Will the rules be used for every page on your site or maybe just a few?Engrossing
I'd like for every page. The syntax !!! <type>\n<The content of the warning> is a Markdown syntax for note boxes and warnings. It produces a <div class="admonishment <type>"></div> tag. I'd like to be able to use it in any post. It's just a blog. As lightweight as I can make it.Anschluss
Alternatively, if I can just find the directory containing the notmyidea theme already installed and modify the css files there, I'd be fine with that dirty hack.Anschluss
It's in the python packages directory (site-packages/pelican/themes/notmyidea/)… but that would break your changes when you update Pelican.Engrossing
Then that hack is useless :-/ Thanks, though. I guess I could copy that theme from the packages directory and point to the static copy instead.Anschluss
E
4

Pelican allows for theme inheritance since version 3, but it seems to work only with the simple theme for some reason…

Here are some less or more hacky ways, still without editing the theme itself:

  • You can include HTML in Markdown, so just inserting <link rel="stylesheet" href="…"> or even <style>…</style> in page/article .md files would work. You can get the Makefile to do it automatically for every page/article. It won't break on updates and the notmyidea theme would get updated with Pelican instead of staying an old static copy.

  • Notmyidea includes a CSS file specified in CSS_FILE settings variable to allow you to use the wide variant (CSS_FILE = "wide.css" in the docs). Looking at the wide.css source, it imports main.css. So, you can create eg. custom.css, import notmyidea's main.css (like the wide.css does), and add your custom rules. And then point CSS_FILE to your custom.css.

Engrossing answered 4/1, 2019 at 22:3 Comment(1)
I really like your first suggestion. When I open the Makefile, I am a little unsure as to how to implement it. It looks like Bash and yaml. Suggestions?Anschluss
C
2

Pelican does not provide theme inheritance--unless you're using the built-in 'simple' theme.

You can override a theme's templates using THEME_TEMPLATES_OVERRIDES, but there's no theme inheritance (including no templates or style inheritance) in Pelican. Yet. This is a killer feature of WordPress, in my opinion.

Also, this feature has an open feature request right now.

Contiguity answered 7/5, 2020 at 0:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.