From 124dc1042f70a7cbe687597b4b3f47098715dd5b Mon Sep 17 00:00:00 2001 From: Herwin Bozet Date: Sun, 20 Oct 2024 22:56:42 +0200 Subject: [PATCH] Added "new" indicator to sidebar Update sidebar.yml, commons.yml, and 4 more files... --- data/sidebar.yml | 11 +++++++++++ data/strings/en/commons.yml | 2 ++ data/strings/fr/commons.yml | 2 ++ data/strings/fr/sidebar.yml | 2 +- templates/base_www.jinja | 3 +++ website/sidebar.py | 5 +++++ 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/data/sidebar.yml b/data/sidebar.yml index 4d052b5..03318ba 100644 --- a/data/sidebar.yml +++ b/data/sidebar.yml @@ -2,6 +2,7 @@ abs_href: "/" icon: fad fa-home active_id: home + has_new_until_utc: 0 - @@ -9,6 +10,7 @@ abs_href: "/articles/" icon: fad fa-newspaper active_id: articles + has_new_until_utc: 0 - @@ -16,31 +18,37 @@ abs_href: "/content/?tags=application;web" icon: fad fa-browser active_id: application + has_new_until_utc: 0 - title_key: text.libraries abs_href: "/content/?tags=library" icon: fad fa-puzzle-piece active_id: library + has_new_until_utc: 0 - title_key: text.electronics abs_href: "/content/?tags=electronic" icon: fad fa-microchip active_id: electronic + has_new_until_utc: 0 - title_key: text.experiments abs_href: "/content/?tags=experiments" icon: fad fa-flask-vial active_id: electronic + has_new_until_utc: 0 - title_key: text.tools abs_href: "/tools" icon: fad fa-toolbox active_id: tools + has_new_until_utc: 0 - title_key: text.downloads raw_href: "https://files.nibblepoker.lu/" icon: fad fa-download active_id: "" + has_new_until_utc: 1760986472 - @@ -48,13 +56,16 @@ abs_href: "/about" icon: fad fa-user active_id: about + has_new_until_utc: 0 - title_key: text.contact abs_href: "/contact" icon: fad fa-mailbox active_id: "" + has_new_until_utc: 0 - title_key: text.links abs_href: "/links" icon: fad fa-link active_id: links + has_new_until_utc: 0 diff --git a/data/strings/en/commons.yml b/data/strings/en/commons.yml index d29aa2b..e9183a0 100644 --- a/data/strings/en/commons.yml +++ b/data/strings/en/commons.yml @@ -21,3 +21,5 @@ user-agent: User-Agent server: Server cpu.architecture: Architecture de CPU + +python: Python diff --git a/data/strings/fr/commons.yml b/data/strings/fr/commons.yml index c50a7af..5c98c95 100644 --- a/data/strings/fr/commons.yml +++ b/data/strings/fr/commons.yml @@ -21,3 +21,5 @@ user-agent: User-Agent server: Serveur cpu.architecture: CPU Architecture + +python: Python diff --git a/data/strings/fr/sidebar.yml b/data/strings/fr/sidebar.yml index b8879e7..e9bd837 100644 --- a/data/strings/fr/sidebar.yml +++ b/data/strings/fr/sidebar.yml @@ -12,7 +12,7 @@ text.libraries: Librairies text.electronics: Électronique text.experiments: Expériences text.3d-print: Impression 3D -text.tools: Outils +text.tools: Utilitaires text.links: Liens text.downloads: Téléchargements text.gitea: Dépôts Git diff --git a/templates/base_www.jinja b/templates/base_www.jinja index 6af4dbb..adebbed 100644 --- a/templates/base_www.jinja +++ b/templates/base_www.jinja @@ -78,6 +78,9 @@

{{ l10n(sidebar_entry.title_key, "sidebar", lang) }} + {% if sidebar_entry.has_new() %} + + {% endif %}

{% else %} diff --git a/website/sidebar.py b/website/sidebar.py index 9007f65..375466e 100644 --- a/website/sidebar.py +++ b/website/sidebar.py @@ -1,4 +1,5 @@ from dataclasses import dataclass, field +from datetime import datetime, timezone from typing import Optional import yaml @@ -9,9 +10,13 @@ class SidebarEntry: title_key: str icon: str active_id: str + has_new_until_utc: int abs_href: Optional[str] = field(default=None) raw_href: Optional[str] = field(default=None) + def has_new(self) -> bool: + return datetime.fromtimestamp(self.has_new_until_utc, tz=timezone.utc) > datetime.now(timezone.utc) + __SIDEBAR_ENTRIES: list[Optional[SidebarEntry]] = list()