Dirk Rüdiger 229c103994 Extended Documentation of the textbundle plugin. 9 lat temu
..
Readme.md 229c103994 Extended Documentation of the textbundle plugin. 9 lat temu
__init__.py ba7c347dc5 Move TextBundle plugin under its own subdirectory 9 lat temu
migrate.sh ba7c347dc5 Move TextBundle plugin under its own subdirectory 9 lat temu
textbundle.py 229c103994 Extended Documentation of the textbundle plugin. 9 lat temu

Readme.md

Textbundle Reader

This plugin helps you creating posts from Textbundles (http://textbundle.org/spec/).

In a nutshell a textbundle is a folder with a .textbundle name suffix and a predefined folder hierarchy. The Markdown text is always in a file text.md, all referenced assets (images, videos, etc.) are located in a subfolder named assets/ and a file info.json (obviously in JSON format) provides some meta data.

Dependency

This plugin needs Markdown to work. Install it with:

pip install Markdown

Installation and configuration

Install the textbundle plugin and add it to the PLUGINS setting in pelicanconf.py:

PLUGINS = [
    'textbundle',
     ...
    ]

Furthermore the content of the ARTICLE_PATHS setting has to be appended to the STATIC_PATHS list.

ARTICLE_PATHS = ['posts']
...
STATIC_PATHS = [
    'posts',
     ...
    ]

The output content pages has to be generated into files index.html inside the folder named after the page slug or article slug. This way the assets can be placed next to the content file and do not interfere with asset files of other textbundles.

A working example of article/page slugs and output URLs are:

ARTICLE_URL = 'post/{slug}/'
ARTICLE_SAVE_AS = 'post/{slug}/index.html'

PAGE_URL = '{slug}/'
PAGE_SAVE_AS = '{slug}/index.html'

Usage

Inside a Markdown file (the file text.md in a textbundle) the files from the assets/ folder are referenced using relative pathnames and the {attach} suffix, as described in the pelican documentation, section "Linking to static files".

An article with the slug "my-blog-post" and an image named screenshot.png in the assets/ folder contains a link like this:

![alt text]({attach}assets/screenshot.png "title text")

Assuming the above mentioned settings in pelicanconf.py the following files are generated in the output folder:

  • posts/my-blog-post/index.html
  • posts/my-blog-post/assets/screenshot.png

Further examples can be found in my personal blog (GitHub, Link).

Generating the boilerplate

To create a new post I have a shell function new_post defined in ~/.bashrc or ~/.zshrc. Running

new_post "My next blogpost"

at the shell prompt creates the file structure of a textbundle in the posts dir of my blog project. The code can be found in my new_post gist. The path names are hardcoded as it's quite easy to adopt the script to one's personal needs.