summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Porte <microjoe@microjoe.org>2020-06-14 08:43:05 +0200
committerRomain Porte <microjoe@microjoe.org>2020-06-14 08:43:05 +0200
commit24397b965109685f8743d5cf0692734a5361c6d5 (patch)
tree3bb15dde4181acdff516078d38c2f9ddf7680dc3
parent112d5aeec235ac06f8877f4e1f8537f885437f4d (diff)
downloadpelican-git-describe-24397b965109685f8743d5cf0692734a5361c6d5.tar.gz
pelican-git-describe-24397b965109685f8743d5cf0692734a5361c6d5.zip
total revamp
-rw-r--r--__init__.py36
-rw-r--r--git_describe.py22
2 files changed, 24 insertions, 34 deletions
diff --git a/__init__.py b/__init__.py
index 80b09f4..8f28cef 100644
--- a/__init__.py
+++ b/__init__.py
@@ -1,35 +1,3 @@
-import subprocess
+from .git_describe import register
-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", "--tags"],
- stdout=subprocess.PIPE, check=True)
- return result.stdout.decode('utf-8').strip()
-
-
-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)
+__all__ = ['register']
diff --git a/git_describe.py b/git_describe.py
new file mode 100644
index 0000000..d33cc0b
--- /dev/null
+++ b/git_describe.py
@@ -0,0 +1,22 @@
+import subprocess
+
+from pelican import signals
+
+
+def git_describe():
+ """Check and return git describe --tags value."""
+ return subprocess \
+ .run(["git", "describe", "--tags"],
+ stdout=subprocess.PIPE, check=True) \
+ .stdout.decode('utf-8').strip()
+
+
+def expand_context(generators):
+ desc = git_describe()
+ for gen in generators:
+ gen.context['git_describe'] = desc
+
+
+def register():
+ """Register Pelican signals to dedicated functions."""
+ signals.all_generators_finalized.connect(expand_context)