API
gresiblos - greyrat's simple blog system.
gresiblos is implemented in Python. It is started on the command line.
gresiblos reads one or multiple blog entry files and embeds them into a template. The template file to use is defined using the option --template <TEMPLATE> / -t <TEMPLATE>.
Generated pages are saved as .html-files per default. You may change it (e.g. to php) using the option --extension <EXTENSION> / -e <EXTENSION>.
The entries may include the meta-information state. You may filter entries to process by setting the option --state <STATE> / -s <STATE> to the one that shall be processed.
The path to store the generated pages into can be defined using the option --destination <PATH> / -d <PATH>. The default is ./.
Besides the generated entries, _gresiblos__ may generate a json-index file that lists the entries with some meta-information. The option --index-output <FILE> will generate the index and save it under the given file name. The index is usually stored as plain json in a single line. For a prettier output, the indentation can be changed using the option --index-indent <INT>.
In addition, files that contain the list of entries embedded into the content section of the template file can be generated. Use the option --chrono-output <FILE> to generate a file with the entries sorted in chronological order and/or the option --alpha-output <FILE> with the entries sorted alphabetically.
To convert contents from markdown to HTML before embedding them, use the option --markdown. When set, the content, the title, and the abstract will be converted. Use the option --degrotesque to apply the degrotesque type setter on the contents before embedding them. Please note that you need to install markdown and/or degrotesque by yourself.
When embedding the meta-information of single blog entries into the template, the topics are split and rendered individually before being embedded. To allow for using them as links, the rendering format can be set using the option --topic-format <TOPIC_FORMAT>. Please note that this string should include something like “[[:topic:]]”, what is replaced by the topic itself. The date meta information is assumed to be in ISO-format (e.g. 2025-01-08 19:26:00), but may be adapted using the option --date-format <DATE_FORMAT>.
The entry/entries to process are given as the last parameter. Multiple entries can be given divided by a ‘,’. Wildcards are accepted as well, so giving ./entries/*.txt will process all files with the extension .txt within the folder entries.
The options can be stored in a configuration file which can be passed to gresiblos using the option --config <CONFIGURATION> / -c <CONFIGURATION>. Options given on the command line will overwrite the options set in the configuration file. Examples
python gresiblos ./entries/*
Generates pages using the default template ./data/template.html and the blog entries located in entries and writes them to ./.
python gresiblos --template mytemplate.html --state release ./entries/*
Generates pages using the template mytemplate.html and the blog entries located in entries and writes them to ./. Processes only entries with state=release. Command line arguments
The script can be started on the command line with the following options:
- --config <CFG_FILE> / -c <CFG_FILE>: Reads the named configuration file
- --template <TEMPLATE_FILE> / -t <TEMPLATE_FILE>: Uses the named template file
- --extension <EXTENSION> / -e <EXTENSION>: The extension to use for the generated files
- --state <STATE> / -s <STATE>: The state the entries must have for being processed
- --destination <PATH> / -d <PATH>: The path to save the generated file(s) into
- --index-output <FILE>: The name of the file to write the index containing information about the entries to
- --chrono-output <FILE>: The name of the file with the list of entries, sorted in chronological order, embedded into the template to
- --alpha-output <FILE>: The name of the file with the list of entries, sorted in alphabetically, embedded into the template to
- --markdown: When set, the contents, the title, and the abstract are converted from markdown to HTML
- --degrotesque: When set, the degrotesque type setter is applied
- --topic-format <TOPIC_FORMAT>: Defines how each of the topics is rendered
- --index-indent <INT>: Defines the indent used for the index file
- --date-format <DATE_FORMAT>: Defines the time format used
- --help / -h: Show a help message
- --version: Show the version information
gresiblos requires one parameter:
- input: The files (entries) to read, separated by ‘,’; accepts wildcards as well
Entry
Represents a blog entry with metadata and content.
Attributes:
Name | Type | Description |
---|---|---|
_fields |
Dict[str, str]
|
A dictionary to store entry fields. |
__init__(fields=None)
Initializes an Entry object with default values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields
|
Dict[str, str]
|
The entry's meta data and content. |
None
|
get(key)
Returns the value of a field by key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key of the field to retrieve. |
required |
Returns:
Type | Description |
---|---|
str
|
The value of the field. |
has_key(key)
Returns whether the key is known.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key of the field to check for. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the named field is stored. |
get_isodate(date_format)
Returns the date in isoformat, if given. Otherwise return None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_format
|
str
|
The date format if it differs from ISO |
required |
Returns:
Type | Description |
---|---|
str
|
The date in isoformat. |
load(filename)
Loads entry data from a filename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The path to the filename containing entry data. |
required |
embed(template, topics_format, apply_markdown=False, prettifier=None)
Embeds entry data into a template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template
|
str
|
The HTML template to embed data into. |
required |
topics_format
|
str
|
The format for topics in the template. |
required |
apply_markdown
|
bool
|
Whether the content/title/abstract shall be parsed as markdown. |
False
|
prettifier
|
Any
|
The degrotesque instance to prettify the content/title/abstract. |
None
|
Returns:
Type | Description |
---|---|
str
|
The template with embedded entry data. |
PlainStorage
Stores metadata of blog entries.
Attributes:
Name | Type | Description |
---|---|---|
_meta |
Dict[str, Dict[str, str]]
|
A dictionary to store metadata of entries. |
__init__()
Initializes a PlainStorage object.
add(filename, entry, date_format)
Adds an entry's metadata to the storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The filename of the entry. |
required |
entry
|
Entry
|
The Entry object containing metadata. |
required |
date_format
|
str
|
The date format if it differs from ISO |
required |
get_meta()
Returns all stored metadata.
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, str]]
|
A dictionary of all stored metadata. |
_get_entries()
Returns all stored entries' metadata as a list.
Returns:
Type | Description |
---|---|
List[Dict[str, str]]
|
A list of entry metadata |
get_entries_chronological()
Returns all stored entries' metadata as a list, sorted by date.
Returns:
Type | Description |
---|---|
List[Dict[str, str]]
|
A list of entry metadata |
get_entries_alphabetical()
Returns all stored entries' metadata as a list, sorted by title (alphabetic).
Returns:
Type | Description |
---|---|
List[Dict[str, str]]
|
A list of entry metadata |
write_list(title, dest_path, template, entries, topic_format, apply_markdown, prettifier)
Generates an unordered list from the given list of entry metadata, embeds it into the given template, and saves the result under the given path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
The title to apply. |
required |
dest_path
|
str
|
The filename of the entry. |
required |
template
|
str
|
The template to fill. |
required |
entries
|
List[Dict[str, str]]
|
A list of entry metadata. |
required |
topic_format
|
str
|
The format of topics to use. |
required |
apply_markdown
|
bool
|
Whether markdown shall be applied. |
required |
prettifier
|
Any
|
The prettyfier to use. |
required |
main(arguments=None)
The main method using parameters from the command line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arguments
|
List[str]
|
A list of command line arguments. |
None
|
Returns:
Type | Description |
---|---|
int
|
The exit code (0 for success). |
- gresiblos
- Entry
- PlainStorage
- write_list
- main
Table of contents