Coder Social home page Coder Social logo

pelican-btoc's Introduction

Pelican-btoc - Automatic generation of TOC for Pelican

pelican-btoc is an open source Pelican plugin to produce table of content for content page. Plugin is based on bootstrap components scrollspy and affix. The plugin is inspired by the similar TOC in the Bootstrap documentation page. The plugin is mostly developed to be used with Markdown content.

Author

Toni Heittola ([email protected]), GitHub, Home page

Installation instructions

Requirements

bs4 is required. To ensure that all external modules are installed, run:

pip install -r requirements.txt

bs4 (BeautifulSoup) for parsing HTML content

pip install beautifulsoup4

In order to regenerate minified CSS and JS files you need also:

rcssmin a CSS Minifier

pip install rcssmin

jsmin a JS Minifier

pip install jsmin

Pelican installation

Make sure you include Bootstrap in your template.

Make sure the directory where the plugin was installed is set in pelicanconf.py. For example if you installed in plugins/pelican-btoc, add:

PLUGIN_PATHS = ['plugins']

Enable pelican-btoc with:

PLUGINS = ['pelican-btoc']

To allow plugin in include css and js files, one needs to add following to the base.html template, in the head (to include css files):

{% if article %}
    {% if article.styles %}
        {% for style in article.styles %}
{{ style }}
        {% endfor %}
    {% endif %}
{% endif %}
{% if page %}
    {% if page.styles %}
        {% for style in page.styles %}
{{ style }}
        {% endfor %}
    {% endif %}
{% endif %}

At the bottom of the page before </body> tag (to include js files):

{% if article %}
    {% if article.scripts %}
        {% for script in article.scripts %}
{{ script }}
        {% endfor %}
    {% endif %}
{% endif %}

{% if page %}
    {% if page.scripts %}
        {% for script in page.scripts %}
{{ script }}
        {% endfor %}
    {% endif %}
{% endif %}

Insert TOC in the page template:

{% if page.toc %}
    {{ page.toc }}
{% endif %}

Insert TOC in the article template:

{% if article.toc %}
    {{ article.toc }}
{% endif %}

Usage

TOC generation is triggered for the page either by setting BTOC metadata for the content (page or article) or inserting [TOC] tag somewhere in the content.

Global parameters

Parameters for the plugin can be set in `pelicanconf.py' with following parameters:

Parameter Type Default Description
BTOC_LEVELS List [1,2] List of integers, Indicates the levels of headers which are included into TOC
BTOC_PANEL_COLOR String panel-primary CSS class used to color the TOC panel in the default template. Possible values: panel-default, panel-primary, panel-success, panel-info, panel-warning, panel-danger
BTOC_HEADER String Content Header used for the TOC panel
BTOC_TEMPLATE String Jinja2 template to wrap the TOC. Parameters panel_color, toc_header, and toc.
BTOC_MINIFIED Boolean True Do we use minified CSS and JS files. Disable in case of debugging.
BTOC_GENERATE_MINIFIED Boolean False CSS and JS files are minified each time, Enable in case of development.
BTOC_DEBUG_PROCESSING Boolean False Show extra information in when run with DEBUG=1
BTOC_TYPE String 'normal' Toc type, possible values normal and alphabet. Use alphabet for glossary type of pages with 1-3 letter headings.

Content wise parameters

Parameter Example value Description
BTOC True Enable TOC for the page
BTOC_LEVELS 1,2 Comma separated integers, Indicates the levels of headers which are included into TOC
BTOC_PANEL_COLOR panel-primary CSS class used to color the TOC panel in the default template. Possible values: panel-default, panel-primary, panel-success, panel-info, panel-warning, panel-danger
BTOC_TYPE normal Toc type, possible values normal and alphabet. Use alphabet for glossary type of pages with 1-3 letter headings.

Example 1:

Title: TOC
Date: 2010-10-03 10:20
BTOC: True
BTOC_LEVELS: 1,2,3
BTOC_TYPE: normal

# H1
Text
    
## Head 1

Text

### Head 1.1

Text
 
### Head 1.2

Text

### Head 1.3

Text 

# H2

Text

## Head 2

Text

### Head 2.1

Text

### Head 2.2

Text

## Head 3

Text

### Head 3.1

Text

### Head 3.2

Text

Example 2:

Title: TOC
Date: 2010-10-03 10:20
BTOC: True
BTOC_LEVELS: 1,2,3
BTOC_TYPE: aplhabet

# A
## Apples 1
## Apples 2
## Apples 3

# O
## Oranges 1
## Oranges 2
## Oranges 3

pelican-btoc's People

Contributors

toni-heittola avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

softquantum

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.