Skip to main content

Pelican plugin that allows to load data from files like JSON or YAML.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

[!WARNING] This project is no longer maintained. The repository has been archived and is read-only. No further updates, issues, or pull requests will be accepted. PyPI packages will still remain available but will be marked as inactive.

If you are interested in continuing development, please feel free to fork this repository and maintain your own version.

Thank you to everyone who used and contributed to this project :heart:

pelican-data-files_banner

pypi_badge licence_badge open_issues_badge closed_issues_badge


Pelican plugin that allows to load data from files like JSON or YAML.

This plugin loads all the data files found in the project's content/data/ directory, and makes them accessible in jinja templates by injecting them into the context (with the prefix DATA_ followed by the name of the file).

This is roughly the default behavior of the well known Jekyll static site generator.

For example, the data of a profile.json file will be accessible from any template via DATA_PROFILE.

Getting started

You can use it directly in a personal project or to build a Pelican theme.

This plugin is avaiable as a python package hosted on PyPI.

Setup

All you have to do is install the latest version of the package with pip:

pip install pelican-data-files

For additional filetypes, you may install variants like this:

# TOML
pip install pelican-data-files[toml]

# YAML
pip install pelican-data-files[yaml]

# Both
pip install pelican-data-files[toml,yaml]

Note: When using multiple data handlers, files with the same name will be prioritized by modified date, so between profile.json and profile.yaml, only the newer / more recently changed one will be picked up!

By default, Pelican will automatically discover and register the plugin (see more here).

To be sure, run this command which displays all the registered plugins, pelican-data-files should be printed:

pelican-plugins

Usage

Place some JSON valid files into data/ folder. Then you can acces your data by querying DATA_<FILE_NAME>["<VAR_NAME>"]

For example, consider a simple file named profile.json with the followed content:

{
  "firstname": "John",
  "lastname": "Doe",
  "age": 25,
  "contact": {
    "phone": "+1 302-516-3307",
    "mail": "john@doe.com"
  }
}

Then, see what following queries return:

DATA_PROFILE["firstname"] => "John"
DATA_PROFILE["age"] => 25
DATA_PROFILE["contact"]["mail"] => "john@doe.com"

So, you can access all the data in data/ folder in jinja templates from pelican context.

Build a theme

It is of course possible to create a theme that uses this plugin, it will not necessarily be dependent on it but must in all cases be designed for. (Usage of DATA_ prefix in theme templates and provide sample data files)

First set the plugin (or its variants, see above) as an install requirement, for example with a package managed with setuptools (setup.py):

...
install_requires=[
  "pelican",
  "pelican-data-files"
],
...

Next, you have to provide sample data files for your theme.

Users can easily fetch the files in their pelican project by running the following command:

pelican-data-files --fetch <THEME_NAME>

This will copy the data/ folder of the theme into the content/data/ folder of their Pelican project.

They will only have to modify the files and generate their site.

Example

orbelican is a theme which use pelican-data-files plugin to build an online resume from orbit-theme.

MIT License

Copyright (c) 2020 vhash

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican_data_files-1.3.0.post1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pelican_data_files-1.3.0.post1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file pelican_data_files-1.3.0.post1.tar.gz.

File metadata

File hashes

Hashes for pelican_data_files-1.3.0.post1.tar.gz
Algorithm Hash digest
SHA256 2d0a79653b43a3462438a71bd9fd1e2076a8d73290cac4dd8d06804e3aa3531b
MD5 46c87617d9a9e65efbe29dfc68b3c0d1
BLAKE2b-256 8ed6afec3eadf2e1950a39605e66e1b138959247d3fda71f26f73be7d7e4c5af

See more details on using hashes here.

File details

Details for the file pelican_data_files-1.3.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for pelican_data_files-1.3.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6d7b65ecc90b775b19c976e752d8490d6466eb485dcb9018b23cb50facf5a18
MD5 25d78cbf01b120575c0b54e36457f60c
BLAKE2b-256 7895d73afea5e6727a0346b5ac04bd8e96672b8849eaa869e9e592de127778e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page