Various settings of Python static blog generation tool'Pelican'

About the settings that I personally want to play with using Pelican, a blog engine made by Python (a tool that generates html from md or rST files).

Please refer to this article for the installation method.

Customize the Path part of the URL

With the default settings, the URL will be (domain) .com / filename. I want to define my own naming convention, not just the file name! At times.

You can set the following two values in pelicanconf.py.

::python
ARTICLE_URL = 'posts/{date:%Y}/{date:%m}/{date:%d}/{slug}/'
ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%m}/{date:%d}/{slug}/index.html'

ARTICLE_URL: URL to be published to the outside

ARTICLE_SAVE_AS: Path to be stored in the folder under output at make html

is not it. From the front, specify the year, month, day, and Slug (article URL part). I think you should read the document for details, but you can set the URL to a character string with the following parameters freely entered.

Other

:::python
ARTICLE_LANG_URL = '{slug}-{lang}.html'
ARTICLE_LANG_SAVE_AS = '{slug}-{lang}.html'

There are some settings, and you can see that you can easily create a multilingual blog just by arranging the html file names separately. The above does so by default, even if you don't explicitly set it.


Organize article files

If you accumulate more and more article files in one folder, it seems that you will not understand the reason as the number increases. The following two methods are effective for keeping things neatly organized.

--Set the category name in the folder and manage the articles by category.

It's very easy to understand if folder name = category name. Settings for that in Pelican

::python
USE_FOLDER_AS_CATEGORY = True

There is. The above is also the same by default when you create a project with quickstart, so if you cut the directory under content, it will be automatically generated as a category name.

By the way, if you want to change the default category

::python
DEFAULT_CATEGORY = ''

You should specify it with. The default value is'misc'. miscellaneous = It's an abbreviation for miscellaneous species.

--Allow sorting by putting the date in the file name

This is also a very convenient setting,

:::python
FILENAME_METADATA = r'(?P<date>\d{4}-\d{2}-\d{2}).*'

If you set, you're done. The value on the right is the default, but it is a regular expression and by writing it like this, the data in yyyy-mm-dd format described in the file name will be automatically linked to the posting date and made into an article. .. Since it is a regular expression, it can be freely set according to the parameters that can be used in Pelican.

:::python
FILENAME_METADATA = r'(?P<date>\d{4}-\d{2}-\d{2})_(?P<slug>.*)'

If you do like this, you can manage it with the file name yyyy-mm-dd_ {title slug}, so I think it will be Author friendly.

That's it.

There are other settings that could be used, so it's interesting to look at the document below.

http://docs.getpelican.com/en/3.1.1/settings.html

Please let me know if there is anything else (laughs).

__Addition __ Added about the introduction of the theme. Try to introduce the theme to Pelican

Recommended Posts

Various settings of Python static blog generation tool'Pelican'
Various processing of Python
Static analysis of Python programs
About various encodings of Python 3
Summary of various for statements in Python
[Python] Summary of array generation (initialization) time! !! !!
1. Statistics learned with Python 1-3. Calculation of various statistics (statistics)
Various format specifications of str.format () method of Python3
[Python] Various combinations of strings and values
[python] Create a list of various character types
1. Statistics learned with Python 1-2. Calculation of various statistics (Numpy)
[Django3] Environment construction and various settings summary [Python3]
Static analysis of Python code with GitLab CI
Introduction of Python
python environment settings
Basics of Python ①
Basics of python ①
# 3 [python3] Various operators
Copy of python
Introduction of Python
Change IP settings to ACL of conoha with python
Old openssl causes problems in various parts of python
Summary of python environment settings for myself [mac] [ubuntu]