blob: 3ccea3bdf869286b4fe0743e1425d05f360d0d16 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
pelican_js_css
===============
This Pelican plugin makes it easy to embed Javascript files and CSS stylesheets into individual Pelican blog articles.
Credit
------
This plugin was inspired by and adopted from the work of [Rob Story](https://github.com/wrobstory) at [pelican_dynamic](https://github.com/wrobstory/pelican_dynamic). I decided to create a similar project on my own instead of forking that one because I'd like to make breaking changes.
Installation
------------
To install the plugin, [follow the instructions on the Pelican plugin page.](https://github.com/getpelican/pelican-plugins) My settings look like the following:
```python
PLUGIN_PATH = 'pelican-plugins'
PLUGINS = ['pelican_css_js']
```
Directory Structure
-------------------
Create ```js``` and ```css``` directories in your ```content``` directory:
```
website/
├── content
│ ├── js/
│ │ └── demo1.js
│ │ └── demo2.js
│ ├── css/
│ │ └── demo1.css
│ ├── article1.rst
│ ├── cat/
│ │ └── article2.md
│ └── pages
│ └── about.md
└── pelicanconf.py
```
and then specify each resource as a comma-separated file name in the ```JavaScripts``` and ```StyleSheets``` keys: (note that these key names are case-insensitive, so ```javascripts``` and ```stylesheets``` would work just fine)
```
Title: Chuletas de programación
Date: 2019-01-20
Lang: es
Slug: chuletas-de-programacion
Author: Jesús E.
JS: demo.js, demo2.js
Styles: demo.css, demo2.css
```
You can also include javascript libraries from a web resource without having to carry the files on your own. If the string starts with `http://` or `https://` it will be treated like a web resource, otherwise the plugin will look for the file under `content/js` for javascript files, and `content/css` for CSS stylesheets.
```
Title: Chuletas de programación
Date: 2019-01-20
Lang: es
Slug: chuletas-de-programacion
Author: Jesús E.
JS: https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js, demo.js, demo2.js
Styles: demo.css, demo2.css
```
Note that the files will be included in the same order specified.
Additions to Templates
----------------------
Finally, in your base template (likely named ```base.html```), you need to add the following in your ```<head>``` section of the HTML:
```
{% if article %}
{% if article.styles %}
{% for style in article.styles %}
{{ style }}
{% endfor %}
{% endif %}
{% endif %}
```
and the following *after* your ```</body>``` tag:
```
{% if article %}
{% if article.js %}
{% for script in article.js %}
{{ script }}
{% endfor %}
{% endif %}
{% endif %}
```
That's it! Run your standard ```make html``` or ```make publish``` commands and your JSS/CSS will be moved and referenced in the output HTML.
|