summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Porte <microjoe@microjoe.org>2017-09-02 21:33:33 +0200
committerRomain Porte <microjoe@microjoe.org>2017-09-02 21:33:33 +0200
commit9b3a59a7e4eaafeed4685a0a81aae79d7fbac4a1 (patch)
tree11dc5a57cf1b5161418611028c69704be4a69a00
downloadpelican-git-describe-9b3a59a7e4eaafeed4685a0a81aae79d7fbac4a1.tar.gz
pelican-git-describe-9b3a59a7e4eaafeed4685a0a81aae79d7fbac4a1.zip
Initial commit
-rw-r--r--__init__.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..b4e5a4a
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,35 @@
+import subprocess
+
+from pelican import signals
+
+
+class GitDescribe:
+ def __init__(self, gen):
+ self.settings = gen.settings
+ self.process()
+
+ def process(self):
+ """Initialization process."""
+ pass
+
+ def defer_process(self):
+ """Check and return git describe value."""
+ result = subprocess.run(["git", "describe"], stdout=subprocess.PIPE,
+ check=True)
+ return result.stdout.decode('utf-8')
+
+
+def initialize(gen):
+ """Function called upon article generator initialization."""
+ gen.plugin_instance = GitDescribe(gen)
+
+
+def fetch(gen, metadata):
+ """Function called upon article generation context fetching."""
+ gen.context['git_describe'] = gen.plugin_instance.defer_process()
+
+
+def register():
+ """Register Pelican signals to dedicated functions."""
+ signals.article_generator_init.connect(initialize)
+ signals.article_generator_context.connect(fetch)