Skip to content

Commit

Permalink
meh
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed Dec 6, 2024
1 parent ef4c4ff commit 07f61db
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 2 deletions.
4 changes: 2 additions & 2 deletions betty/project/extension/cotton_candy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Provide Betty's default theme.
Provide the Cotton Candy theme.
"""

from __future__ import annotations
Expand Down Expand Up @@ -119,7 +119,7 @@ class CottonCandy(
EntryPointProvider,
):
"""
Provide Betty's default front-end theme.
The Cotton Candy theme.
"""

_plugin_id = "cotton-candy"
Expand Down
98 changes: 98 additions & 0 deletions betty/project/extension/raspberry_mint/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 %}
<p>
{% 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 %}
</p>
<p>
{% set liberta_lankester_label -%}
<a href="{{ project.ancestry['person']['betty-demo-liberta-lankester'] | localized_url }}">Liberta 'Betty' Lankester</a>
{%- 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 %}
</p>
{% endif %}
{% if project.extensions['cotton-candy'].configuration.featured_entities %}
<div class="featured">
<div class="featured-entities">
{% for entity_reference in project.extensions['cotton-candy'].configuration.featured_entities %}
<div class="featured-entity">
{% with entity = project.ancestry[entity_reference.entity_type][entity_reference.entity_id] %}
{% include [
'entity/featured--' + entity.plugin_id() + '.html.j2',
'entity/featured.html.j2',
] %}
{% endwith %}
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% endblock %}
124 changes: 124 additions & 0 deletions betty/project/extension/raspberry_mint/assets/templates/base.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!doctype html>
<html lang="{{ localizer.locale }}"
prefix="foaf: http://xmlns.com/foaf/0.1/ og: http://ogp.me/ns# rel: http://purl.org/vocab/relationship/">
<head>
{% include 'head.html.j2' %}
<link rel="manifest" href="{{ '/betty.webmanifest' | static_url }}">
</head>
<body>
<script>
document.body.classList.add('with-js');
</script>
<div id="page">
<nav id="nav-primary">
<a id="site-title" href="{{ '/index.html' | localized_url }}" title="{{ project.configuration.title | localize }}">{{ project.configuration.title | localize }}</a>
<div id="search"
data-betty-search-index="{{ '/search-index.json' | localized_url }}">
<div class="overlay-controls">
<span class="overlay-control overlay-close" title="{% trans %}Exit the search{% endtrans %}">{% trans %}Exit the search{% endtrans %}</span>
</div>
<form>
{% set search_keywords_example_person_name = project.ancestry['person'] | select('public') | map(attribute='name') | first | default(none) %}
{% if search_keywords_example_person_name %}
{% set search_keywords_example -%}
{% filter forceescape %}
{% trans example = search_keywords_example_person_name.label | localize -%}
E.g. "{{ example }}"
{%- endtrans %}
{% endfilter %}
{%- endset %}
{% endif %}
<input id="search-query" type="search"{% if search_keywords_example is defined %} placeholder="{{ search_keywords_example }}"{% endif %}>
<label for="search-query" title="Search">Search</label>
</form>
<section id="search-expanded">
<h2 class="visually-hidden">Search</h2>
<p id="search-instructions">
{% trans -%}
Use <kbd>↑</kbd> and <kbd>↓</kbd> to navigate results, or <kbd>esc</kbd> to exit the search.
{%- endtrans %}
</p>
<div id="search-results-twilight">
<div id="search-results-container"></div>
</div>
</section>
</div>
<div id="nav-sections" class="nav-primary-expandable">
<h2 class="nav-primary-action">{% trans %}Menu{% endtrans %}</h2>
<div class="nav-primary-expanded">
<ul class="nav-secondary">
{% for entity_type_configuration in project.configuration.entity_types.values() | selectattr('generate_html_list') %}
{% set entity_type = project.entity_type_repository.get(entity_type_configuration.id) %}
<li>
<a href="{{ entity_type | localized_url }}">
{% if entity_type.plugin_id() == 'event' %}
{% trans %}Timeline{% endtrans %}
{% else %}
{{ entity_type.plugin_label_plural() | localize }}
{% endif %}
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
{% if page_resource is defined and project.configuration.locales.multilingual %}
<div id="nav-locale" class="nav-primary-expandable">
<h2 class="nav-primary-action">{% trans %}Language{% endtrans %}</h2>
<div class="nav-primary-expanded">
<ul class="nav-secondary">
{% set ns = namespace(available_locales=[]) %}
{% for available_locale_configuration in project.configuration.locales.values() %}
{% set available_locale_data = available_locale_configuration.alias | locale_get_data %}
{% do ns.available_locales.append((available_locale_configuration.locale, available_locale_data.get_display_name())) %}
{% endfor %}
{% for available_locale, available_locale_name in ns.available_locales | sort(attribute='1') %}
<li><a href="{{ page_resource | localized_url(locale=available_locale) }}" hreflang="{{ available_locale }}" lang="{{ available_locale }}" rel="alternate">{{ available_locale_name }}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
</nav>
<div id="content">
{% if page_title is defined %}
<h1>{{ page_title }}</h1>
{% 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 %}
<section id="external-links">
<h2>
{% trans %}External links{% endtrans %}
{% with url = page_resource | localized_url ~ '#external-links'%}
{% include 'permalink.html.j2' %}
{% endwith %}
</h2>
<ul>
{% for link in links %}
<li>
<a href="{{ link.url }}"{% if link.locale is not none %} hreflang="{{ link.locale }}"{% endif %}{% if link.relationship is not none %} rel="{{ link.relationship }}"{% endif %}{% if link.media_type is not none %} type="{{ link.media_type }}"{% endif %}>{{ link.label | localize or link.url }}</a>
{% if link.description %}
<div class="meta">{{ link.description | localize }}</div>
{% endif %}
</li>
{% endfor %}
</ul>
</section>
{% endif %}
{% endif %}
{% include 'references.html.j2' %}
</div>
<footer>
{% include 'footer.html.j2' %}
</footer>
</div>
{% 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' %}
</body>
</html>
5 changes: 5 additions & 0 deletions betty/project/extension/raspberry_mint/webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"engines": {
"node": ">= 20"
}
}

0 comments on commit 07f61db

Please sign in to comment.