Skip to main content

ShowCommits Preprocessor

ShowCommits is a preprocessor that appends the history of Git commits corresponding to the current processed file to its content.

Installation

$ pip install foliantcontrib.showcommits

Config

To enable the preprocessor, add showcommits to preprocessors section in the project config:

preprocessors:
    - showcommits

The preprocessor has a number of options with the following default values:

preprocessors:
    - showcommits:
        repo_path: !rel_path ./    # Path object that points to the current Foliant project’s top-level (“root”) directory when the preprocessor initializes
        try_default_path: true
        remote_name: origin
        self-hosted: gitlab
        protocol: https
        position: after_content
        date_format: year_first
        escape_shortcodes: true
        escape_html: true
        template: |
            ## File History

            {{startcommits}}
            Commit: [{{hash}}]({{url}}), author: [{{author}}]({{email}}), date: {{date}}

            {{message}}

            ```diff
            {{diff}}
            ```
            {{endcommits}}
        targets: []

repo_path : Path to the locally cloned copy of the Git repository that the current Foliant project’s files belong to.

try_default_path : Flag that tells the preprocessor to try to use the default repo_path if user-specified repo_path does not exist.

remote_name : Identifier of remote repository; in most cases you don’t need to override the default value.

self-hosted : String that defines the rules of commit’s web URL anchor generation when a self-hosted Git repositories management system with web interface is used. Supported values are: github for GitHub, gitlab for GitLab, and bitbucket for BitBucket. If the repo fetch URL hostname is github.com, gitlab.com, or bitbucket.org, the corresponding rules are applied automatically.

protocol : Web interface URL prefix of a repos management system. Supported values are https and http.

position : String that defines where the history of commits should be placed. Supported values are: after_content for concatenating the history with the currently processed Markdown file content, and defined_by_tag for replacing the tags <commits></commits> with the history.

date_format : Output date format. If the default value year_first is used, the date “December 11, 2019” will be represented as 2019-12-11. If the day_first value is used, this date will be represented as 11.12.2019.

escape_shortcodes : Flag that tells the preprocessor to replace shortcodes with escaped shortcodes in diffs, for example: {{< shortcode >}} with {{</* shortcode */>}}.

escape_html : Flag that tells the preprocessor to replace HTML control characters with corresponding HTML entities in commit messages and diffs: & with &amp;, < with &lt;, > with &gt;, " with &quot;.

template : Template to render the history of commits. If the value is a string that contains one or more newlines (\n) or double opening curly braces ({{), it is interpreted as a template itself. If the value is a string without newlines and any double opening curly braces, or a Path object, it is interpreted as a path to the file that contains a template. Template syntax is described below.

targets : Allowed targets for the preprocessor. If not specified (by default), the preprocessor applies to all targets.

Usage

You may override the default template to customize the commits history formatting and rendering. Feel free to use Markdown syntax, HTML, CSS, and JavaScript in your custom templates.

In templates, a number of placeholders is supported.

{{startcommits}} : Beginning of the list of commits that is rendered within a loop. Before this placeholder, you may use some common stuff like an introducing heading or a stylesheet.

{{endcommits}} : End of the list of commits. After this placeholder, you also may use some common stuff like a paragraph of text or a script.

The following placeholders affect only between the {{startcommits}} and {{endcommits}}.

{{hash}} : First 8 digits of the commit hash, e.g. deadc0de.

{{url}} : Web URL of commit with an anchor that points to the certain file, e.g. https://github.com/foliant-docs/foliant/commit/67138f7c#diff-478b1f78b2146021bce46fbf833eb636. If you don’t use a repos management system with web interface, you don’t need this placeholder.

{{author}} : Author name, e.g. Artemy Lomov.

{{email}} : Author email, e.g. artemy@lomov.ru.

{{date}} : Formatted date, e.g. 2019-12-11.

{{message}} : Commit message, e.g. Bump version to 1.0.1..

{{diff}} : Diff between the currently processed Markdown file at a certain commit and the same file at the previous state.

Metadata

Release files for foliantcontrib.showcommits 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for foliantcontrib.showcommits 1.0.6
File Size Uploaded
foliantcontrib_showcommits-1.0.6.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for foliantcontrib.showcommits 1.0.6
File Interpreter ABI Platform
foliantcontrib_showcommits-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 15.9 kB

Release files / foliantcontrib_showcommits-1.0.6.tar.gz

Download URL foliantcontrib_showcommits-1.0.6.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b998ab431133080f84ef66eb829a8e8d8ec7f27a3dd457e40c0c012e90e27848
BLAKE2b-256 checksum
How to use checksums
a5e54653cf587827752eadaeb60938eb49050003aa06ae39bc8d1d2bbcb8aae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / foliantcontrib_showcommits-1.0.6-py3-none-any.whl

Download URL foliantcontrib_showcommits-1.0.6-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df54e966141bc54e54c032e97c198201d4112937a57f1c471fb9bef5125862a0
BLAKE2b-256 checksum
How to use checksums
136801d22796f8470dca4a9ce6f65b27b5a71ed415347eb06ea4490ec54b11f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page