Search code examples
pythoncssstatic-sitepelican

Add CSS rules to Pelican without creating a theme


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?


Solution

  • 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.