Additional CSS from markup plugins?

16 views
Skip to first unread message

Christopher Arndt

unread,
Apr 19, 2016, 2:00:22 PM4/19/16
to nikola-discuss
Is there a way for a ReST directive or shortcode plugin to add additional CSS files or snippets to the page (i.e. the head), other than adding it directly to the plugin's output (which will may result in duplicated code).

Chris Warrick

unread,
Apr 19, 2016, 2:15:15 PM4/19/16
to Nikola—Discuss
Not really. It’s easier to ask users to add CSS themselves — either
via EXTRA_HEAD_DATA, files/assets/custom.css, or their own CSS files
(if applicable). This is the easiest and sanest option, because while
you could modify EXTRA_HEAD_DATA programmatically or use the
oft-forgotten template hooks mechanism to add your own things, most
people won’t like it (hard to customize, performance hit).

You also couldn’t do it reliably on per-post basis, because the output
from the compiler (reST/Markdown/…) may end up on multiple pages (at
least 2 in default setup, possibly even more with *_ARE_INDEXES
settings), and those pages may contain multiple posts with the desired
CSS.

(If you are writing a custom blog template, you can make a conditional
inclusion like we do for MathJax.)

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Christopher Arndt

unread,
Apr 27, 2016, 12:59:55 PM4/27/16
to nikola-discuss

On Tuesday, April 19, 2016 at 8:15:15 PM UTC+2, Chris Warrick wrote:
On 19 April 2016 at 20:00, Christopher Arndt <spotlig...@gmail.com> wrote:
> Is there a way for a ReST directive or shortcode plugin to add additional
> CSS files
 
Not really. It’s easier to ask users to add CSS themselves

Ok, thanks. The template hooks might be what I'm looking for, though. Allowing the user to override the provided CSS efficiently needs to addressed though, that's true.

Maybe it would be an idea to provide a Nikola command that allows to install extra CSS files from somewhere on the net in the files/asset folder? Or hooks for the plugin install command? Just thinking out loud here...

BTW, the reason I was asking is this plugin I wrote:

https://gist.github.com/SpotlightKid/94b3e9c7cfac467ff920d09efe601e0e

which needs additional CSS from noembed.com, so that the embedded content looks right. The additional problem here is, that, depending on which content is embedded by the plugin, you only need a subset of the collection of CSS rules from noembed.com.
Reply all
Reply to author
Forward
0 new messages