Pelican plugin that adds a link to post source content
Project description
Show Source: A Plugin for Pelican
This Pelican plugin allows you to place a link to your posts’ source content files in the same way that Sphinx does. It works for both pages and articles.
Installation
This plugin can be installed via:
python -m pip install pelican-show-source
For more detailed plugin installation instructions, please refer to the Pelican Plugin Documentation.
Configuration
To enable the plugin, ensure that you have SHOW_SOURCE_ON_SIDEBAR = True
or SHOW_SOURCE_IN_SECTION = True
in your settings file.
SHOW_SOURCE_ALL_POSTS = True
will show the source for all posts, instead of only posts with the source explicitly made available (see below.) By default, this is False
.
The option SHOW_SOURCE_PRESERVE_EXTENSION
(False
by default) controls the extension of the output source file. If True
, the file will have the same extension as the real source document (.rst
, .md
, etc). Otherwise, it will be a plain-text .txt
file.
Making Source Available for Posts
In order to mark posts so that their source may be seen, use the following metadata fields (unless overridden) for reStructuredText documents:
:show_source: True
Alternatively, for Markdown syntax:
Show_source: True
The plugin will render your source document URL to a corresponding article.show_source_url
(or page.show_source_url
) attribute, which is then accessible in the site templates.
Show Source in the Templates
To get the “show source” links to display in the article or page you will have to modify your theme, either as a sidebar display or at the foot of an article.
Article or Page Sidebar Display
How to get the source link to appear in the sidebar using the pelican-bootstrap3 theme:
{% if SHOW_SOURCE_ON_SIDEBAR %}
{% if (article and article.show_source_url) or (page and page.show_source_url) %}
<li class="list-group-item"><h4><i class="fa fa-tags fa-file-text"></i><span class="icon-label">This Page</span></h4>
<ul class="list-group">
<li class="list-group-item">
{% if article %}
<a href="{{ SITEURL }}/{{ article.show_source_url }}">Show source</a>
{% elif page %}
<a href="{{ SITEURL }}/{{ page.show_source_url }}">Show source</a>
{% endif %}
</li>
</ul>
</li>
{% endif %}
{% endif %}
Article Footer Display
Following is some code (yes, pelican-bootstrap3 again) to enable a source link at the bottom of an article:
{% if SHOW_SOURCE_IN_SECTION %}
{% if article and article.show_source_url %}
<section class="well" id="show-source">
<h4>This Page</h4>
<ul>
<a href="{{ SITEURL }}/{{ article.show_source_url }}">Show source</a>
</ul>
</section>
{% endif %}
{% endif %}
Overriding Default Plugin Behaviour
The default behaviour of the plugin is that revealing source is enabled on a case-by-case basis. This can be changed by the use of SHOW_SOURCE_ALL_POSTS = True
in the settings file. This does mean that the plugin will publish all source documents no matter whether show_source
is set in the metadata or not.
Unless overridden, each document is saved as the article or page slug attribute with a .txt
extension.
So for example, if your configuration had ARTICLE_SAVE_AS
configured like so:
ARTICLE_SAVE_AS = "posts/{date:%Y}/{date:%m}/{slug}/index.html"
… your static HTML post and source text document will be like the following:
posts/2016/10/welcome-to-my article/index.html
posts/2016/10/welcome-to-my article/welcome-to-my article.txt
You can add the SHOW_SOURCE_FILENAME
variable in your settings file to override the source file name, so you could set the following:
SHOW_SOURCE_FILENAME = "my_source_file.txt"
So with the ARTICLE_SAVE_AS
configured as above, the files would be saved
thus:
posts/2016/10/welcome-to-my article/index.html
posts/2016/10/welcome-to-my article/my_source_file.txt
This is the same behaviour for pages as well.
Contributing
Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.
To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.
License
This project is licensed under the AGPL-3.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pelican-show-source-1.1.0.tar.gz
.
File metadata
- Download URL: pelican-show-source-1.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.7.10 Linux/5.4.0-1046-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1962350a79fdd951b2750f2ce99f6d68b5053edb1662eadbb734c34abbd8ce06 |
|
MD5 | f04751a615c71acf117981396d8123a1 |
|
BLAKE2b-256 | 2754e50dd11dee88e8c3b2a84f52c6fc81b32fa3998bc6903f644daf85cf9f54 |
File details
Details for the file pelican_show_source-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: pelican_show_source-1.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.7.10 Linux/5.4.0-1046-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5adf10b41ee5684389dffbfa3e64fecd17a8a00d57cbe72688dcc25b38a0bfe9 |
|
MD5 | 7379840d1bd2a8aa8c39fc5ca2c6eefe |
|
BLAKE2b-256 | 7356f93f7a617112bf3025bbb039312c5443e60d6e7f8973f25249eae974d8e5 |