From 8eb4dc9ea279335fa6b7db1bc3cdfee5b914fd40 Mon Sep 17 00:00:00 2001 From: hedy Date: Sat, 23 Mar 2024 19:48:41 +0800 Subject: Timeline: Migrate to Markdown source files - initial implementation - The timeline app is introduced, moved from the home app. - Add a basic README.md to illustrate the overall code breakdown of the app as it is in the current stage. - Two entries are added for now. - Add ability to link headers using the slug portion of the filename. - The way markdown files are fetched is similar to that of the resources app - using the AppConfig ready() function, all resources are ensured to be only fetched once when the app is first laoded. I debated whether to introduce the new functionality in the home app instead, without creating a new app. Eventually I decided extracting it to a standalone app now is better as it allows easier extension of functionality in the future. The home app can remain as it is to only server the `/` homepage. The timeline CSS is kept the same, as with the structure of the timeline HTML template. Once the CSS rewrite PR is merged, it's relatively easy to fix conflicts here (again, since timeline is now its own app, with the CSS file and HTML template moved - extra advantage). References to `home:timeline` are updated to use `timeline:index` throughout the codebase, as far as my ripgrep search could go. The format of the markdown + YAML entries are still up for debate, so I've only added the first two entries for now. They can be completely overwritten in the future once the formats are decided by using a script to convert all the data from my JSON file into individual markdown files: http://0x0.st/Xr78.txt This link should last for at least a few months. (Originally saved on https://paste.pythondiscord.com/KPJA, but it expires on 12th April 2024.) --- pydis_site/apps/timeline/apps.py | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pydis_site/apps/timeline/apps.py (limited to 'pydis_site/apps/timeline/apps.py') diff --git a/pydis_site/apps/timeline/apps.py b/pydis_site/apps/timeline/apps.py new file mode 100644 index 00000000..8f27297f --- /dev/null +++ b/pydis_site/apps/timeline/apps.py @@ -0,0 +1,45 @@ +from pathlib import Path + +from django.apps import AppConfig +import frontmatter +import markdown + +from pydis_site import settings + + +ENTRIES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "timeline", "entries") + + +class TimelineConfig(AppConfig): + """AppConfig instance for Timeline app.""" + + name = 'pydis_site.apps.timeline' + + def ready(self) -> None: + """Fetch all the timeline entries.""" + self.entries = [] + + for path in ENTRIES_PATH.rglob("*.md"): + metadata, content = frontmatter.parse(path.read_text(encoding="utf-8")) + + md = markdown.Markdown() + html = str(md.convert(content)) + + # Strip `.md` file extension from filename and split it into the + # date (for sorting) and slug (for linking). + key, slug = path.name[:-3].split("_") + entry = { + "key": key, + "slug": slug, + "title": metadata["title"], + "date": metadata["date"], + "icon": metadata["icon"], + # This key might not be used if the icon uses the pydis logo. + "icon_color": metadata.get("icon_color"), + "content": html, + } + + self.entries.append(entry) + + # Sort the entries in reverse-chronological order. + self.entries.sort(key=lambda e: e['key'], reverse=True) -- cgit v1.2.3 From 046199eb91008ba79170b58406a7fadc43f193ab Mon Sep 17 00:00:00 2001 From: hedy Date: Sat, 6 Apr 2024 12:56:13 +0800 Subject: Timeline: Use pydis blurple as default icon background color --- pydis_site/apps/timeline/apps.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pydis_site/apps/timeline/apps.py') diff --git a/pydis_site/apps/timeline/apps.py b/pydis_site/apps/timeline/apps.py index 8f27297f..37a61e93 100644 --- a/pydis_site/apps/timeline/apps.py +++ b/pydis_site/apps/timeline/apps.py @@ -28,14 +28,19 @@ class TimelineConfig(AppConfig): # Strip `.md` file extension from filename and split it into the # date (for sorting) and slug (for linking). key, slug = path.name[:-3].split("_") + + icon_color = metadata.get("icon_color") + # Use the pydis blurple as the default background color. + if not icon_color or metadata["icon"] == "pydis": + icon_color = "has-background-primary" + entry = { "key": key, "slug": slug, "title": metadata["title"], "date": metadata["date"], "icon": metadata["icon"], - # This key might not be used if the icon uses the pydis logo. - "icon_color": metadata.get("icon_color"), + "icon_color": icon_color, "content": html, } -- cgit v1.2.3