Created
November 28, 2018 17:51
-
-
Save juanAFernandez/f67f36cf64698cb24306470af146d118 to your computer and use it in GitHub Desktop.
A json reader plugin to do Pelican able to read json files to render in html instead of Markdown or RST files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pelican import signals | |
from pelican.readers import BaseReader | |
import json | |
class JsonReader(BaseReader): | |
enabled = True | |
def __init__(self, settings): | |
super(JsonReader, self).__init__(settings) | |
file_extensions = ['json'] | |
def read(self, filename): | |
with open(filename, 'rt', encoding='UTF-8') as f: | |
json_data = json.loads(f.read()) | |
parsed = {} | |
for key, value in json_data.items(): | |
parsed[key] = self.process_metadata(key, value) | |
# All is processed as metadata, content is ''. | |
return '', parsed | |
def add_reader(readers): | |
readers.reader_classes['json'] = JsonReader | |
def register(): | |
signals.readers_init.connect(add_reader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# Adding a plugin | |
PLUGIN_PATHS = ['pineapple_pelican_plugins'] | |
PLUGINS = [ | |
'json_reader' | |
] | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment