summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans-Nikolai Viessmann2020-08-02 18:56:02 +0200
committerHans-Nikolai Viessmann2020-08-02 18:56:02 +0200
commit4dc5b7a7781df3e74b6c3c1a99adeb74021dbf34 (patch)
tree1222caa6e384aab61dafdf48331af759bbeb7805
downloadpelican-plugin-link-cloud-master.tar.gz
pelican-plugin-link-cloud-master.zip
inital commitHEADmaster
-rw-r--r--__init__.py1
-rw-r--r--linkcloud.py64
2 files changed, 65 insertions, 0 deletions
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..844718a
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1 @@
+from .linkcloud import *
diff --git a/linkcloud.py b/linkcloud.py
new file mode 100644
index 0000000..e74c9ca
--- /dev/null
+++ b/linkcloud.py
@@ -0,0 +1,64 @@
+import os
+import json
+import logging
+import random
+from yattag import Doc
+from pelican.generators import Generator
+from pelican import signals
+
+logger = logging.getLogger(__name__)
+
+links = ""
+
+# bulma color classes for buttons
+colors = [
+ 'is-primary',
+ 'is-link',
+ 'is-info',
+ 'is-success',
+ 'is-warning',
+ 'is-danger',
+ 'is-primary is-light',
+ 'is-link is-light',
+ 'is-info is-light',
+ 'is-success is-light',
+ 'is-warning is-light',
+ 'is-danger is-light'
+]
+
+def gen_link_cloud (gen):
+ global links
+ global colors
+
+ path = os.path.join (gen.settings.get ('PATH'), 'links.json')
+ data = None;
+
+ try:
+ with open (path, 'r') as f:
+ data = json.load (f);
+ except Exception as e:
+ logger.error('Exception occurred: %s', e, exc_info=gen.settings.get('DEBUG', False))
+
+ doc, tag, text = Doc().tagtext()
+ for cat, entries in data.items ():
+ with tag ('h2'):
+ text (cat)
+
+ with tag ('div', klass='buttons'):
+ for entry in entries:
+ if 'show' in entry and entry['show'] is not False:
+ if 'date' in entry:
+ mtitle = '{}; viewed on {}'.format (entry['title'], entry['date'])
+ else:
+ mtitle = '{}.'.format (entry['title'])
+ with tag ('a', klass='button {}'.format (random.choice (colors)), href=entry['href'], title=mtitle):
+ text (entry['name'])
+
+ links = doc.getvalue ()
+
+def add_links (gen, metadata):
+ gen.context['links'] = links
+
+def register ():
+ signals.initialized.connect(gen_link_cloud)
+ signals.page_generator_context.connect(add_links)