

[Pelican] Create URL Based on File Path
source link: http://siongui.github.io/2018/10/17/pelican-create-url-based-on-file-path/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[Pelican] Create URL Based on File Path
October 17, 2018
Pelican static site generator - Create URL of page or article based on the full path relative to the content source directory.
Problem
for example, the following is the path of a page:
content/pages/intro.rst
The URL of the page will be:
/intro/
The following is the path of a article:
content/articles/category/myproduct.rst
The URL of the article will be:
/category/myproduct/
Solution
We will create a custom metadata field called urlpath. The value of urlpath is extracted from article/page's path relative to the content source directory. Then the value of urlpath will be used to determine the URL of the article/page. You do not need to modify the file content of articles/pages.
The solution is to set PATH_METADATA, PAGE_URL, PAGE_SAVE_AS, ARTICLE_URL, ARTICLE_SAVE_AS in pelicanconf.py as follows:
PATH_METADATA = '(articles|pages)/(?P<urlpath>[-a-zA-Z0-9/]*)\.rst' ARTICLE_URL = '{urlpath}/' ARTICLE_SAVE_AS = '{urlpath}/index.html' PAGE_URL = '{urlpath}/' PAGE_SAVE_AS = '{urlpath}/index.html'
Tested on: Ubuntu Linux 18.04, Python 2.7.15rc1, Pelican 3.7.1.
References:
Recommend
-
32
Put All Your Pelican Posts in One Org File Pelican is a static site generator. Out of the box it...
-
9
According to the Apple Photos internal SQLite database, this is the most aesthetically pleasing photograph I have ever taken of a pelican:
-
15
Improve your Pelican based website SEO by adding canonical url Posted on Wed 14 October 2020 in Development You may have notice that a few days ago th...
-
16
Publish your Pelican blog on Github pages via Travis-CIPublish your Pelican blog on Github pages via Travis-CI Thu 09 January 2014This blog is powered by Pelican, and until recently I have rendered the HTML pages on my local machine...
-
16
PyCon US 2018 CFP, Python Bytes and Pelican PyCon US 2018 is coming up in Cleveland, Ohio on May 9th-17th. The call for p...
-
12
How to Create Your First Static Site with Pelican and Jinja2Pelican is an incredibly well-built Python tool for cr...
-
12
前端有的时候需要对 url 或者 http 请求进行处理,比如有的 api 不需要带 token 访问,有的直接请求第三方接口。之前处理的方式是简单的包含判断,后来发现这样不够严谨也容易出问题。正确的做法是用正则去匹配,但是自己写的也难保不会出错,所以就找了第三方...
-
10
在迁移到这里之前,洒家使用了 3 年博客园平台(链接)。个人认为博客园、CSDN 这种博客网站有很多缺点,例如不能真正掌握自己的数据,不方便定制,环境和氛围不好。此...
-
4
Andrej’s notes Hi from MiniDebConf in Hamburg!
-
4
Swift URL absoluteString versus path 17 August 2023 Foundation’s...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK