项目作者: toni-heittola

项目描述 :
Pelican plugin to generate glossary
高级语言: Python
项目地址: git://github.com/toni-heittola/pelican-bglossary.git
创建时间: 2018-10-15T09:18:36Z
项目社区:https://github.com/toni-heittola/pelican-bglossary

开源协议:MIT License

下载


Pelican-bglossary - Glossary for Pelican

pelican-bglossary is an open source Pelican plugin to produce glossary from yaml data structure. The plugin is developed to be used with Markdown content and Bootstrap 3 based template.

Author

Toni Heittola (toni.heittola@gmail.com), GitHub, Home page

Installation instructions

Requirements

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

  1. pip install -r requirements.txt

bs4 (BeautifulSoup) for parsing HTML content

  1. pip install beautifulsoup4

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-bglossary, add:

  1. PLUGIN_PATHS = ['plugins']

Enable pelican-bglossary with:

  1. PLUGINS = ['pelican-bglossary']

Insert glossary list or panel into the page template:

  1. {% if page.bglossary %}
  2. {{ page.bglossary }}
  3. {% endif %}

Insert glossary list or panel into the article template:

  1. {% if article.bglossary %}
  2. {{ article.bglossary }}
  3. {% endif %}

Usage

Glossary generation is triggered for the page either by setting BGLOSSARY metadata for the content (page or article) or using <div> with class bglossary.

Layouts

  • bglossary, full glossary

There is two layout modes available: panel and list.

Glossary registry

Registry has two parts:

  1. - **`glossary`** containing information of each item in glossary

Example yaml-file:

  1. glossary:
  2. - term: supervised learning
  3. definition: learning method which learns from labeled examples
  4. fi: ohjattu oppiminen
  5. de: Überwachtes Lernen
  6. es: aprendizaje supervisado
  7. fr: apprentissage supervisé
  8. wikipedia: https://en.wikipedia.org/wiki/Supervised_learning
  9. intra_link: unsupervised learning
  10. - term: unsupervised learning
  11. definition: machine learning technique to learn from unlabeled data
  12. fi: ohjaamaton oppiminen
  13. de: Unüberwachtes Lernen
  14. es: aprendizaje no supervisado
  15. fr: apprentissage non supervisé
  16. wikipedia: https://en.wikipedia.org/wiki/Unsupervised_learning
  17. intra_link: supervised learning

The default templates support following fields:

  • term
  • definition
  • translation fields: fi, de, es, and fr
  • wikipedia
  • wiktionary
  • intra_link, cross linking between terms

Parameters

The parameters can be set in global, and content level. Globally set parameters are are first overwritten content meta data, and finally with div parameters.

Global parameters

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

Parameter Type Default Description
BGLOSSARY_SOURCE String YAML-file to contain glossary registry, see example format above.
BGLOSSARY_TEMPLATE Dict of Jinja2 templates Two templates can be set for panel and list
BGLOSSARY_ITEM_TEMPLATE Dict of Jinja2 templates Two templates can be set for panel and list
BGLOSSARY_PANEL_COLOR String panel-primary CSS class used to color the panel template in the default template. Possible values: panel-default, panel-primary, panel-success, panel-info, panel-warning, panel-danger
BGLOSSARY_HEADER String Content Header text
BGLOSSARY_SORT Boolean False Sorting of the listing based on term
BGLOSSARY_DEBUG_PROCESSING Boolean False Show extra information in when run with DEBUG=1

Content wise parameters

Parameter Example value Description
BGLOSSARY True Enable bglossary listing for the page
BGLOSSARY_SOURCE content/data/glossary.yaml Personnel registry file
BGLOSSARY_MODE panel Layout type, panel or list
BGLOSSARY_PANEL_COLOR panel-info CSS class used to color the panel template in the default template. Possible values: panel-default, panel-primary, panel-success, panel-info, panel-warning, panel-danger
BGLOSSARY_HEADER Personnel Header text
BGLOSSARY_FIELDS email, photo, affiliation comma separated list of field to be shown
BGLOSSARY_SORT True Sorting of the listing based on term

Example:

  1. Title: Test page
  2. Date: 2017-01-05 10:20
  3. Category: test
  4. Slug: test-page
  5. Author: Test Person
  6. bglossary: True
  7. bglossary_header: Glossary
  8. bglossary_fields: wikipedia, wiktionary, fi, fr, es, intra_link

Personnel listing is available in template in variable page.bglossary or article.bglossary

Div wise parameters

Valid for <div> class bglossary:

Parameter Example value Description
data-source content/data/glossary.yaml Glossary registry file
data-mode panel Layout type, panel or list
data-header Glossary Header text
data-panel-color panel-info CSS class used to color the panel template in the default template. Possible values: panel-default, panel-primary, panel-success, panel-info, panel-warning, panel-danger
data-fields email, photo, affiliation comma separated list of field to be shown
data-sort True Sorting of the listing based on term

Example listing:

  1. <div class="bglossary" data-source="content/data/glossary.yaml" data-set="set1" data-fields="wikipedia, wiktionary, de, fi, fr, es, intra_link"></div>