Package: pelican-data-files
Pelican plugin that allows to load data from files like JSON or YAML.This plugin loads all the data files found in the project'scontent/data/directory, and makes them accessible in jinja templates by injecting them into the context (with the prefixDATA_followed by the name of the file).This is roughly the default behavior of the well knownJekyllstatic site generator.For example, the data of aprofile.jsonfile will be accessible from any template viaDATA_PROFILE.Getting startedYou can use it directly in a personal project or to build aPelican theme.This plugin is avaiable as apython packagehosted on PyPI.SetupAll you have to do is install the latest version of the package with pip:pipinstallpelican-data-filesFor additional filetypes, you may install variants like this:# TOMLpipinstallpelican-data-files[toml]# YAMLpipinstallpelican-data-files[yaml]# Bothpipinstallpelican-data-files[toml,yaml]Note: When using multiple data handlers, files with the same name will be prioritized by modified date, so betweenprofile.jsonandprofile.yaml, only the newer / more recently changed one will be picked up!By default, Pelican will automatically discover and register the plugin (see morehere).To be sure, run this command which displays all the registered plugins,pelican-data-filesshould be printed:pelican-pluginsUsagePlace some JSON valid files intodata/folder. Then you can acces your data by queryingDATA_<FILE_NAME>["<VAR_NAME>"]For example, consider a simple file namedprofile.jsonwith 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"]=>25DATA_PROFILE["contact"]["mail"]=>"john@doe.com"So, you can access all the data indata/folder in jinja templates from pelican context.Build a themeIt 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 ofDATA_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 thedata/folder of the theme into thecontent/data/folder of their Pelican project.They will only have to modify the files and generate their site.Exampleorbelicanis a theme which use pelican-data-files plugin to build an online resume from orbit-theme.MIT LicenseCopyright (c) 2020 vhashPermission 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.