Add CSS rules to Pelican without creating a theme
Question:
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?
Answers:
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
.
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.
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?
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 theMakefile
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 importsmain.css
. So, you can create eg.custom.css
, import notmyidea’smain.css
(like thewide.css
does), and add your custom rules. And then pointCSS_FILE
to yourcustom.css
.
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.