-
Notifications
You must be signed in to change notification settings - Fork 2
/
pelicanconf.py
81 lines (61 loc) · 2.69 KB
/
pelicanconf.py
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
# -*- coding: utf-8 -*-
# @Author: Kristinita
# @Date: 2017-01-17 17:43:09
# @Last Modified time: 2022-09-12 07:44:04
"""Pelican configuration file.
For development. publishconf.py — for publishing.
"""
import sys
from datetime import date
# [INFO] Enable import from current working directory.
#
# [NOTE] Doesn't need “os” module:
# https://github.com/getpelican/pelican-blog/blob/master/publishconf.py
#
# [WARNING] I can't find better solution for it:
# https://stackoverflow.com/a/28154841/5951529
sys.path.append(".")
# [INFO] Import from a directory above.
# In my case, I import functions from a “jinja_filters” folder:
# https://stackoverflow.com/a/11096846/5951529
sys.path.append("..")
# [LEARN][PYTHON] Use IPython %load and %whos, that view variables of current file:
# https://ipython.readthedocs.io/en/stable/interactive/magics.html#built-in-magic-commands
# https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-loadpy
# https://stackoverflow.com/a/21034906/5951529
# https://stackoverflow.com/a/634581/5951529
# [INFO] Disable flake8 errors:
# https://stackoverflow.com/a/38338146/5951529
#
# [NOTE] “noqa”, not “NOQA” works for Anaconda:
# https://stackoverflow.com/a/46759770/5951529
#
# [INFO] Disable pylint errors:
# https://stackoverflow.com/a/48836605/5951529
# pylint: disable=wrong-import-position
from pelican_settings_loader import DEV_SETTINGS # noqa: E402
from pelican_settings_loader import kira_load_settings # noqa: E402
from jinja_filters.jinja_filter_all import jinja_filter_all
from jinja_filters.jinja_filter_any import jinja_filter_any
# pylint: enable=wrong-import-position
# [INFO] Insert current year to templates:
# https://bernhard.scheirle.de/posts/2016/February/29/how-to-keep-your-copyright-year-up-to-date-using-jinja-filters/
CURRENTYEAR = date.today().year
"""
[INFO] Adding custom Jinja filters to Pelican:
https://docs.getpelican.com/en/latest/settings.html?highlight=jinja_filters#basic-settings
https://web.archive.org/web/20210726001021/https://linkpeek.com/blog/how-to-add-a-custom-jinja-filter-to-pelican.html
[INFO] Jinja filter can also be added as a Pelican plugin:
https://undefinedvalue.com/adding-a-jinja2-filter-with-a-pelican-plugin.html
[NOTE] “JINJA_FILTERS” variable works solely in Python files, not in YAML
[FIXME][ISSUE] Add “all()” and “any()” filters to the Jinja Filters plugin:
https://github.com/pelican-plugins/jinja-filters
"""
JINJA_FILTERS = {
'all': jinja_filter_all,
'any': jinja_filter_any
}
# [INFO] Convert Python dictionary to variables.
# [NOTE] “locals()” and “globals” is a bad idea:
# https://stackoverflow.com/a/36059129/5951529
globals().update(kira_load_settings(DEV_SETTINGS))