From 080959c3f2b7260980607518de354ce82e9fec87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 10 Nov 2021 09:52:52 +0100 Subject: [PATCH 1/2] POC commit for a Controller Hotlist page --- content/pages/controller-hotlist.md | 9 +++ pelicanconf.py | 6 ++ plugins/discourse_hotlist/__init__.py | 3 + .../discourse_hotlist/discourse_hotlist.py | 61 +++++++++++++++++++ theme/templates/pages/controller-hotlist.html | 42 +++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 content/pages/controller-hotlist.md create mode 100644 plugins/discourse_hotlist/__init__.py create mode 100644 plugins/discourse_hotlist/discourse_hotlist.py create mode 100644 theme/templates/pages/controller-hotlist.html diff --git a/content/pages/controller-hotlist.md b/content/pages/controller-hotlist.md new file mode 100644 index 000000000..88ff7d0ab --- /dev/null +++ b/content/pages/controller-hotlist.md @@ -0,0 +1,9 @@ +--- +title: Controller Hotlist +template: pages/controller-hotlist +controllers: + replaced_by_discourse_hotlist_py: + name: Hercules RMX 2 + forum_link: https://mixxx.discourse.group/t/custom-midi-mapping-hercules-rmx-2-0-1-3 + heat: 78 +... diff --git a/pelicanconf.py b/pelicanconf.py index 377c714c9..36fd70dab 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -89,6 +89,7 @@ PLUGINS = [ "author_metadata", "download_metadata", + "discourse_hotlist", "draft_override", "md_yaml", ] @@ -125,6 +126,11 @@ def __init__(self, url, title, context, css="", children=()): "Press", "Navigation bar link to Mixxx Press page", ), + MenuItem( + "/controller-hotlist", + "Hot-List", + "Navigation bar link to Mixxx Controller Hotlist", + ), MenuItem( "/contact", "Contact & Team", diff --git a/plugins/discourse_hotlist/__init__.py b/plugins/discourse_hotlist/__init__.py new file mode 100644 index 000000000..94f004c87 --- /dev/null +++ b/plugins/discourse_hotlist/__init__.py @@ -0,0 +1,3 @@ +from .discourse_hotlist import register + +__all__ = ["register"] diff --git a/plugins/discourse_hotlist/discourse_hotlist.py b/plugins/discourse_hotlist/discourse_hotlist.py new file mode 100644 index 000000000..9fa4cc04b --- /dev/null +++ b/plugins/discourse_hotlist/discourse_hotlist.py @@ -0,0 +1,61 @@ +import json +import logging +import datetime +import urllib.request +from pelican import signals + +# from pydiscourse import DiscourseClient + + +def format_size(num, suffix="B"): + """Convert a file size in bytes into a human-readable format.""" + for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"): + if abs(num) < 1024.0: + return "%3.1f%s%s" % (num, unit, suffix) + num /= 1024.0 + return "%.1f%s%s" % (num, "Yi", suffix) + + +def url_add_query_params(original_url, query_params): + """Returns the URL with the given query parameters added.""" + url = urllib.parse.urlparse(original_url) + query = urllib.parse.parse_qs(url.query) + query.update(query_params) + query = urllib.parse.urlencode(query) + return urllib.parse.urlunparse( + (url.scheme, url.netloc, url.path, url.params, query, url.fragment) + ) + + +def page_generator_context(page_generator, metadata): + """ + Iterate through page objects and augment the download page's package data + with information from the download manifest file (if specified). + """ + logger = logging.getLogger(__name__) + + controllers = metadata.get("controllers", {}) + + # check if the page has controllers in the metadata + if controllers: + # remove dummy entry + controllers.clear() + + for x in range(10): + streetno = {} + streetno["name"] = "Fancy Controller" + streetno["heat"] = x + streetno[ + "forum_link" + ] = "https://mixxx.discourse.group/t/denon-sc2000/11122" + controllers[str(x)] = streetno + + # client = DiscourseClient( + # 'https://mixxx.discourse.group/', + # api_username='username', + # api_key='areallylongstringfromdiscourse') + + +def register(): + """ Subscribe to Pelican's signals. """ + signals.page_generator_context.connect(page_generator_context) diff --git a/theme/templates/pages/controller-hotlist.html b/theme/templates/pages/controller-hotlist.html new file mode 100644 index 000000000..cb960161f --- /dev/null +++ b/theme/templates/pages/controller-hotlist.html @@ -0,0 +1,42 @@ +{% extends "base.html" %} + +{% block title %}{% trans %}List the hottest controllers based on forums activity{% endtrans %}{% endblock %} + +{% block body %} + +
+

Controller Hotlist

+

{% trans %}This is the list of hottest controllers based on forums activity.{% endtrans %}

+

+

+

+
+ + + +{% endblock %} From 14b57395708e88e8abedb6f8bce19fd2794ea222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Fri, 12 Nov 2021 19:32:44 +0100 Subject: [PATCH 2/2] Remove the menu link to the controller hot-list --- pelicanconf.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index 36fd70dab..1c8ba2c22 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -126,11 +126,6 @@ def __init__(self, url, title, context, css="", children=()): "Press", "Navigation bar link to Mixxx Press page", ), - MenuItem( - "/controller-hotlist", - "Hot-List", - "Navigation bar link to Mixxx Controller Hotlist", - ), MenuItem( "/contact", "Contact & Team",