-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpelican_version.py
35 lines (27 loc) · 1.19 KB
/
pelican_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Article list generator plugin for Pelican
================================
The idea is to generate a (json) file to be able to communicate togehter with Ajax calls
This will allow creating single page endless scroll without the need of using server side files
"""
from pelican import signals
from jinja2 import Environment, FileSystemLoader
import os
def generate_version(generator):
versionPath = generator.settings.get('VERSION_PATH', 'content')
path = os.path.dirname(os.path.realpath(__file__))
outputPath = generator.settings.get('OUTPUT_VERSION_PATH', 'output')
env = Environment(loader=FileSystemLoader(path))
template = env.get_template('version.html')
try:
currentVersionFile = open(versionPath + '/currentVersion', 'r')
currentVersion = int(currentVersionFile.read()) + 1
except:
currentVersion = 0
output_from_parsed_template = template.render(version=currentVersion)
with open(versionPath + "/currentVersion", "w+b") as fh:
fh.write(output_from_parsed_template)
with open(outputPath + "/version", "wb") as fh:
fh.write(output_from_parsed_template)
def register():
signals.finalized.connect(generate_version)