Giter VIP home page Giter VIP logo

mkdocs-markdownextradata-plugin's Introduction

mkdocs-markdownextradata-plugin

Build Status

A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template

usecase

As a user with variables that need to be inserted at the markdown level, not the template level.
I need a mkdocs plugin that will inject my `extras` variables into the markdown template before it gets rendered to html.
So that I can build my markdown pages with different values for images, urls, client_names, etc. 

Installation

Note: This package requires MkDocs version 0.17 or higher.

Install the package with pip:

pip install mkdocs-markdownextradata-plugin

Enable the plugin in your mkdocs.yml:

plugins:
    - search
    - markdownextradata: {}

You are then able to use the mkdocs extra: {} hash to pass context data into your files

Note: If you have no plugins entry in your config file yet, you'll likely also want to add the search plugin. MkDocs enables it by default if there is no plugins entry set, but now you have to enable it explicitly.

Features

Use Extra Variables in your markdown files

The variables you define in the mkdown.yml extra: slot will become available in your templates

site_name: My fantastic site

plugins:
    - search
    - markdownextradata

extra:
  customer:
    name: Your name here
    web: www.example.com
    salt: salt.example.com

and then in your *.md files

{{ customer.name }}
<a href="{{ customer.web }}">{{ customer.web }}</a>

Using external data files

If the extra: {} hash is not enough for your data then you are able to make use of external yaml files to provide that context data

plugins:
    - search
    - markdownextradata:
        data: path/to/datafiles

or if you have multiple locations provide a comma (,) separated list of locations

plugins:
    - search
    - markdownextradata:
        data: path/to/datafiles, another/path/to/datafiles

if you leave markdownextradata.data empty

plugins:
    - search
    - markdownextradata

by default it will search in the folder where your mkdocs.yml is kept and in the docs folder for another folder called _data

i.e. ./docs/_data/site.yaml - available as '{{ site.whatever_variable_in_the_yaml}}'

If this path is found, the plugin will read all .yml|.yaml and .json files inside it and add the data in them, to the template context.

If inside your data folder you have a directory and a file file called [path/to/datafiles/]sections/captions.yaml - where [path/to/datafiles/] is the path in your configuration - the data inside that file will be available in your templates as sections.captions.whatever_variable_in_the_yaml.

Testing

virtualenv venv -p python3.7
source venv/bin/activate
python setup.py test
pytest test

Contributing

From reporting a bug to submitting a pull request: every contribution is appreciated and welcome. Report bugs, ask questions and request features using Github issues. If you want to contribute to the code of this project, please read the Contribution Guidelines.

Contributors

mkdocs-markdownextradata-plugin's People

Contributors

realorangeone avatar retorquere avatar rosscdh avatar sebastienlevert avatar stard0g avatar

Watchers

 avatar

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.