Skip to main content

Pelican Custom CSS makes it easy to embed custom CSS into individual Pelican articles and pages.

Project description

Pelican Custom CSS

Pelican Custom CSS makes it easy to embed custom CSS into individual Pelican articles and pages.

How

pip install pelican-custom-css

Next, create a css directory in your content directory.

website/
├── content
│   ├── css/
│   │   ├── your_custom_style1.css
│   │   └── your_custom_style2.css
│   ├── article1.md
│   └── pages
│       └── about.md
└── pelicanconf.py

And then add each resource as a comma-separated file name in the CSS tag:

Title: Mejor sin Wordpress
Date: 2017-02-09 18:51
Tags: programación, Wordpress, generador de páginas estáticas, generador de sitios web estáticos, rendimiento, eficiencia, comodidad, desventajas
Category: Desarrollo web
Author: jorgesumle
Slug: mejor-sin-wordpress
CSS: your_custom_style1.css, your_custom_style2.css

Finally, in your base template (likely named base.html), you need to add the following in your <head> tag:

{% if article %}
    {% if article.styles %}
        {% for style in article.styles %}
            {{ style|format(SITEURL) }}
        {% endfor %}
    {% endif %}
{% endif %}

So, the template I use for my blog now looks like the following:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset=utf-8">
    <title>{% block title %} {{SITENAME}} {% endblock %}</title>
    <link rel="stylesheet" href="{{ SITEURL }}/theme/css/style.css" type="text/css">
    {% if article %}
        {% if article.styles %}
            {% for style in article.styles %}
                {{ style|format(SITEURL) }}
            {% endfor %}
        {% endif %}
    {% endif %}
  </head>
  <body>
    <div class=container>
        {% block header %}
            {% include "header.html" %}
        {% endblock %}

        <div class="content">
        {% block content %} {% endblock %}
        </div>

        {% block footer %}
            {% include "footer.html" %}
        {% endblock %}
    </div>
  </body>
</html>

The previous code only works for articles. For most people, that's enough. If you want to enable custom CSS in pages too insert the following code your <head> tag...

{% if page %}
    {% if page.styles %}
        {% for style in page.styles %}
            {{ style|format(SITEURL) }}
        {% endfor %}
    {% endif %}
{% endif %}

That's it! You can now generate and publish your site normally, for example using ghp-import if you're using Github Pages or the standard make html or make publish commands from Pelican and your CSS will be copied and referenced in the right places.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican_custom_css-0.0.3.tar.gz (50.8 kB view details)

Uploaded Source

Built Distribution

pelican_custom_css-0.0.3-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

Details for the file pelican_custom_css-0.0.3.tar.gz.

File metadata

  • Download URL: pelican_custom_css-0.0.3.tar.gz
  • Upload date:
  • Size: 50.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pelican_custom_css-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5415cd5aea935cd1796d5fd054015e96bec0028c48479e56393bbfb20daa3d2c
MD5 c4c306a89e8cb7d65c54c5d87b7c07dd
BLAKE2b-256 e7011d3e321a106d72e79dca3b6e54022d1fbd1cd6a5b145dc2c2afcb03d8973

See more details on using hashes here.

File details

Details for the file pelican_custom_css-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pelican_custom_css-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8d4f2952e3789ec14a89dfc86206a2642fed9ba0efdb4ad05bca476340d840e6
MD5 9da41699fdd4e1f62f7cb4060fd10dcf
BLAKE2b-256 556cd5b5a6a107ce516a1545ab95244d4700e3d1eb2e4190dc51498c8fe9dfdc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page