From 4a1d5dc5606adacef1d8760e03629ff14199b75b Mon Sep 17 00:00:00 2001 From: John Aziz Date: Wed, 6 May 2026 00:49:27 +0300 Subject: [PATCH] feat: add links to view and edit pages in github --- src/pallets/__init__.py | 1 + src/pallets/models.py | 20 ++++++++++++++++++++ src/pallets/static/style.css | 24 ++++++++++++++++++++++++ src/pallets/templates/blog/post.html | 2 ++ src/pallets/templates/icons/eye.svg | 1 + src/pallets/templates/icons/pencil.svg | 1 + src/pallets/templates/macros.html | 8 ++++++++ src/pallets/templates/page.html | 6 +++++- src/pallets/templates/person.html | 5 +++-- src/pallets/templates/project.html | 2 ++ 10 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/pallets/templates/icons/eye.svg create mode 100644 src/pallets/templates/icons/pencil.svg create mode 100644 src/pallets/templates/macros.html diff --git a/src/pallets/__init__.py b/src/pallets/__init__.py index a333ba2..f5da93f 100644 --- a/src/pallets/__init__.py +++ b/src/pallets/__init__.py @@ -20,6 +20,7 @@ def create_app() -> Flask: SERVER_NAME="127.0.0.1:5000", SQLALCHEMY_ENGINES={"default": "sqlite://"}, FORWARDED=dict(FOR=0, PROTO=0, HOST=0, PORT=0, PREFIX=0), + GITHUB_REPO="https://github.com/pallets/website", ) app.config.from_prefixed_env() diff --git a/src/pallets/models.py b/src/pallets/models.py index c821f04..5697c84 100644 --- a/src/pallets/models.py +++ b/src/pallets/models.py @@ -8,6 +8,7 @@ import sqlalchemy as sa import sqlalchemy.orm as orm from feedgen.feed import FeedGenerator +from flask import current_app from flask import url_for from . import db @@ -17,6 +18,7 @@ class BasePage(Model): content_prefix: str = "" + content_ext: str = ".md" __abstract__ = True path: orm.Mapped[str] = orm.mapped_column(primary_key=True) is_dir: orm.Mapped[bool] = orm.mapped_column(default=False) @@ -31,6 +33,23 @@ def __init__(self, **kwargs: t.Any) -> None: path = posixpath.join(self.content_prefix, posixpath.dirname(self.path)) self.content_html = render_content(self.content, path) + @property + def content_file(self) -> str: + prefix = posixpath.join("content", self.content_prefix, "") + if self.is_dir: + return f"{prefix}{self.path}/index{self.content_ext}" + return f"{prefix}{self.path}{self.content_ext}" + + @property + def github_edit_url(self) -> str: + repo = current_app.config["GITHUB_REPO"] + return f"{repo}/edit/main/{self.content_file}" + + @property + def github_view_url(self) -> str: + repo = current_app.config["GITHUB_REPO"] + return f"{repo}/blob/main/{self.content_file}" + class Page(BasePage): __tablename__ = "page" @@ -38,6 +57,7 @@ class Page(BasePage): class Person(BasePage): content_prefix = "people" + content_ext = ".toml" __tablename__ = "person" name: orm.Mapped[str] nickname: orm.Mapped[str | None] diff --git a/src/pallets/static/style.css b/src/pallets/static/style.css index 307f211..2cf5730 100644 --- a/src/pallets/static/style.css +++ b/src/pallets/static/style.css @@ -28,6 +28,30 @@ footer { align-items: start; } +.edit-this-page { + float: right; + display: inline-flex; + align-items: center; + font-size: 1rem; + color: var(--pico-muted-color); + margin-top: 0.3em; + padding: 0.25em 0.6em; + border-radius: var(--pico-border-radius); + transition: color 0.2s, background-color 0.2s; + vertical-align: middle; +} + +.edit-this-page:hover { + color: var(--pico-primary); + background-color: var(--pico-muted-background); +} + +.edit-this-page svg { + width: 1em; + height: 1em; + fill: currentColor; +} + footer ul { display: grid; } diff --git a/src/pallets/templates/blog/post.html b/src/pallets/templates/blog/post.html index e557081..1197c0d 100644 --- a/src/pallets/templates/blog/post.html +++ b/src/pallets/templates/blog/post.html @@ -1,6 +1,8 @@ {% extends "layout.html" %} +{% from "macros.html" import page_links %} {% block page %} + {{ page_links(page.github_view_url, page.github_edit_url) }}

{{ page.title }}

Posted by {{ page.author_name }} on {{ page.published.strftime("%Y-%m-%d") }}
diff --git a/src/pallets/templates/icons/eye.svg b/src/pallets/templates/icons/eye.svg new file mode 100644 index 0000000..bde19a2 --- /dev/null +++ b/src/pallets/templates/icons/eye.svg @@ -0,0 +1 @@ + diff --git a/src/pallets/templates/icons/pencil.svg b/src/pallets/templates/icons/pencil.svg new file mode 100644 index 0000000..1784b1c --- /dev/null +++ b/src/pallets/templates/icons/pencil.svg @@ -0,0 +1 @@ + diff --git a/src/pallets/templates/macros.html b/src/pallets/templates/macros.html new file mode 100644 index 0000000..4c0332c --- /dev/null +++ b/src/pallets/templates/macros.html @@ -0,0 +1,8 @@ +{% macro page_links(view_url, edit_url) %} + + {% include "icons/pencil.svg" %} + + + {% include "icons/eye.svg" %} + +{% endmacro %} diff --git a/src/pallets/templates/page.html b/src/pallets/templates/page.html index 56b03d0..86c241d 100644 --- a/src/pallets/templates/page.html +++ b/src/pallets/templates/page.html @@ -1,3 +1,7 @@ {% extends "layout.html" %} +{% from "macros.html" import page_links %} -{% block page %}{{ page.content_html | safe }}{% endblock %} +{% block page %} + {{ page_links(page.github_view_url, page.github_edit_url) }} + {{ page.content_html | safe }} +{% endblock %} diff --git a/src/pallets/templates/person.html b/src/pallets/templates/person.html index 55c2029..f8fb310 100644 --- a/src/pallets/templates/person.html +++ b/src/pallets/templates/person.html @@ -1,12 +1,13 @@ {% extends "layout.html" %} +{% from "macros.html" import page_links %} {% block page %}
{% if page.name %} -

{{ page.name }}

+

{{ page.name }} {{ page_links(page.github_view_url, page.github_edit_url) }}

{{ page.nickname }}

{% else %} -

{{ page.nickname }}

+

{{ page.nickname }} {{ page_links(page.github_view_url, page.github_edit_url) }}

{% endif %}
+ {{ page_links(page.github_view_url, page.github_edit_url) }} {{ page.content_html | safe }}
{% endblock %}