From 07f61db8b4191b43388e24582613cec82d696828 Mon Sep 17 00:00:00 2001 From: Bart Feenstra Date: Fri, 6 Dec 2024 23:19:51 +0000 Subject: [PATCH] meh --- .../extension/cotton_candy/__init__.py | 4 +- .../extension/raspberry_mint/__init__.py | 98 ++++++++++++++ .../assets/public/localized/index.html.j2 | 39 ++++++ .../assets/templates/base.html.j2 | 124 ++++++++++++++++++ .../raspberry_mint/webpack/package.json | 5 + 5 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 betty/project/extension/raspberry_mint/__init__.py create mode 100644 betty/project/extension/raspberry_mint/assets/public/localized/index.html.j2 create mode 100644 betty/project/extension/raspberry_mint/assets/templates/base.html.j2 create mode 100644 betty/project/extension/raspberry_mint/webpack/package.json diff --git a/betty/project/extension/cotton_candy/__init__.py b/betty/project/extension/cotton_candy/__init__.py index 0e557f070..1dac8163b 100644 --- a/betty/project/extension/cotton_candy/__init__.py +++ b/betty/project/extension/cotton_candy/__init__.py @@ -1,5 +1,5 @@ """ -Provide Betty's default theme. +Provide the Cotton Candy theme. """ from __future__ import annotations @@ -119,7 +119,7 @@ class CottonCandy( EntryPointProvider, ): """ - Provide Betty's default front-end theme. + The Cotton Candy theme. """ _plugin_id = "cotton-candy" diff --git a/betty/project/extension/raspberry_mint/__init__.py b/betty/project/extension/raspberry_mint/__init__.py new file mode 100644 index 000000000..fc4e53df9 --- /dev/null +++ b/betty/project/extension/raspberry_mint/__init__.py @@ -0,0 +1,98 @@ +""" +Provide the Raspberry Mint theme. +""" + +from __future__ import annotations + +from pathlib import Path +from typing import TYPE_CHECKING, final, Self + +from typing_extensions import override + +from betty.html import CssProvider +from betty.jinja2 import ( + Jinja2Provider, +) +from betty.locale.localizable import static +from betty.os import link_or_copy +from betty.plugin import ShorthandPluginBase +from betty.project.extension import Theme, Extension +from betty.project.extension.maps import Maps +from betty.project.extension.trees import Trees +from betty.project.extension.webpack import Webpack +from betty.project.extension.webpack.build import EntryPointProvider +from betty.project.generate import GenerateSiteEvent +from betty.typing import private + +if TYPE_CHECKING: + from betty.project import Project + from betty.plugin import PluginIdentifier + from betty.event_dispatcher import EventHandlerRegistry + from collections.abc import Sequence + + +async def _generate_logo(event: GenerateSiteEvent) -> None: + await link_or_copy( + event.project.logo, event.project.configuration.www_directory_path / "logo.png" + ) + + +@final +class RaspberryMint( + ShorthandPluginBase, + Theme, + CssProvider, + Jinja2Provider, + EntryPointProvider, +): + """ + The Raspberry Mint theme. + """ + + _plugin_id = "raspberry-mint" + _plugin_label = static("Raspberry Mint") + + @private + def __init__(self, project: Project, public_css_paths: Sequence[str]): + super().__init__(project) + self._public_css_paths = public_css_paths + + @override + @classmethod + async def new_for_project(cls, project: Project) -> Self: + static_url_generator = await project.static_url_generator + return cls(project, [static_url_generator.generate("/css/cotton-candy.css")]) + + @override + def register_event_handlers(self, registry: EventHandlerRegistry) -> None: + registry.add_handler(GenerateSiteEvent, _generate_logo) + + @override + @classmethod + def depends_on(cls) -> set[PluginIdentifier[Extension]]: + return {Webpack} + + @override + @classmethod + def comes_after(cls) -> set[PluginIdentifier[Extension]]: + return {Maps, Trees} + + @override + @classmethod + def assets_directory_path(cls) -> Path: + return Path(__file__).parent / "assets" + + @override + @classmethod + def webpack_entry_point_directory_path(cls) -> Path: + return Path(__file__).parent / "webpack" + + @override + def webpack_entry_point_cache_keys(self) -> Sequence[str]: + # @todo Finish this + return () + + @override + @property + def public_css_paths(self) -> Sequence[str]: + return self._public_css_paths diff --git a/betty/project/extension/raspberry_mint/assets/public/localized/index.html.j2 b/betty/project/extension/raspberry_mint/assets/public/localized/index.html.j2 new file mode 100644 index 000000000..882d7d8b1 --- /dev/null +++ b/betty/project/extension/raspberry_mint/assets/public/localized/index.html.j2 @@ -0,0 +1,39 @@ +{% extends 'base.html.j2' %} +{% set page_title %} + {% trans project_title=project.configuration.title | localize -%} + Welcome to {{ project_title }} + {%- endtrans %} +{% endset %} +{% block page_content %} + {% if 'demo' in project.extensions %} +

+ {% trans -%} + Betty is an application that takes a family tree and builds a website out of it, much like the one you are viewing right now. The more information your genealogical research contains, the more interactivity Betty can add to your site, such as media galleries, maps, and browsable family trees. + {%- endtrans %} +

+

+ {% set liberta_lankester_label -%} + Liberta 'Betty' Lankester + {%- endset %} + {% trans liberta_lankester_label = liberta_lankester_label -%} + Betty was named after {{ liberta_lankester_label }}, and this website shows a small sample of her family history. You can browse the pages about her and some of her family to get an idea of what a Betty site looks like. + {%- endtrans %} +

+ {% endif %} + {% if project.extensions['cotton-candy'].configuration.featured_entities %} + + {% endif %} +{% endblock %} diff --git a/betty/project/extension/raspberry_mint/assets/templates/base.html.j2 b/betty/project/extension/raspberry_mint/assets/templates/base.html.j2 new file mode 100644 index 000000000..eef886685 --- /dev/null +++ b/betty/project/extension/raspberry_mint/assets/templates/base.html.j2 @@ -0,0 +1,124 @@ + + + + {% include 'head.html.j2' %} + + + + +
+ +
+ {% if page_title is defined %} +

{{ page_title }}

+ {% endif %} + {% block page_content %}{% endblock %} + {% if page_resource is has_links %} + {% set links = page_resource.links | list %} + {% set links = (links | select_localizeds(include_unspecified=true) | list + links | selectattr('locale', 'none') | list) | unique | list %} + {% if links | length > 0 %} + + {% endif %} + {% endif %} + {% include 'references.html.j2' %} +
+ +
+{% include 'linked-data.html.j2' %} +{% include 'stylesheets.html.j2' %} +{% do 'cotton-candy' | webpack_entry_point_js %} +{% include 'webpack-entry-loader.html.j2' %} +{% include 'scripts.html.j2' %} + + diff --git a/betty/project/extension/raspberry_mint/webpack/package.json b/betty/project/extension/raspberry_mint/webpack/package.json new file mode 100644 index 000000000..6650340e7 --- /dev/null +++ b/betty/project/extension/raspberry_mint/webpack/package.json @@ -0,0 +1,5 @@ +{ + "engines": { + "node": ">= 20" + } +}