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..1c8ba2c22 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -89,6 +89,7 @@ PLUGINS = [ "author_metadata", "download_metadata", + "discourse_hotlist", "draft_override", "md_yaml", ] 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 %}