From 8dd11256c31bd59bfd6dd978658445131e088a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Tue, 25 Jun 2024 14:07:29 +0200 Subject: [PATCH] Widgets callable with Jinja macros Versions for blocks Multiple content repertories --- .../blocks/{footer.en.html => en/footer.html} | 4 +-- .../blocks/{header.en.html => en/header.html} | 0 .../blocks/{footer.fr.html => fr/footer.html} | 4 +-- .../blocks/{header.fr.html => fr/header.html} | 0 content/pages/{test/dir => }/a_page.md | 2 +- {galae-content => content}/pages/fr-index.md | 0 content/templates/jinja2/base.html | 3 -- content/templates/jinja2/blocks/block.html | 4 +-- .../blocks/{navbar.en.html => en/navbar.html} | 0 .../blocks/{navbar.fr.html => fr/navbar.html} | 0 content/templates/jinja2/image.html | 3 -- content/templates/jinja2/widgets/navbar.html | 2 +- .../pages/{test => }/another_page.md | 2 +- galae-content/pages/{en => }/en-index.md | 0 .../generateur-enregistrements-dns.md | 0 .../pages}/temoignages-clients.md | 0 jssg/jinja2.py | 9 ----- jssg/models.py | 33 +++++-------------- jssg/settings.py | 2 +- jssg/urls.py | 14 ++++---- jssg/views.py | 6 +--- 21 files changed, 26 insertions(+), 62 deletions(-) rename common-content/templates/jinja2/blocks/{footer.en.html => en/footer.html} (93%) rename common-content/templates/jinja2/blocks/{header.en.html => en/header.html} (100%) rename common-content/templates/jinja2/blocks/{footer.fr.html => fr/footer.html} (93%) rename common-content/templates/jinja2/blocks/{header.fr.html => fr/header.html} (100%) rename content/pages/{test/dir => }/a_page.md (51%) rename {galae-content => content}/pages/fr-index.md (100%) rename content/templates/jinja2/blocks/{navbar.en.html => en/navbar.html} (100%) rename content/templates/jinja2/blocks/{navbar.fr.html => fr/navbar.html} (100%) delete mode 100644 content/templates/jinja2/image.html rename galae-content/pages/{test => }/another_page.md (54%) rename galae-content/pages/{en => }/en-index.md (100%) rename galae-content/pages/{fr => }/generateur-enregistrements-dns.md (100%) rename {content/pages/fr => galae-content/pages}/temoignages-clients.md (100%) diff --git a/common-content/templates/jinja2/blocks/footer.en.html b/common-content/templates/jinja2/blocks/en/footer.html similarity index 93% rename from common-content/templates/jinja2/blocks/footer.en.html rename to common-content/templates/jinja2/blocks/en/footer.html index 4fe0e1f..08e11f0 100644 --- a/common-content/templates/jinja2/blocks/footer.en.html +++ b/common-content/templates/jinja2/blocks/en/footer.html @@ -18,7 +18,7 @@ Home
  • - Customer testimonials (FR) + Customer testimonials (FR)
  • Download the price @@ -41,7 +41,7 @@ Account management
  • - DNS record generator (FR) + DNS record generator (FR)
  • diff --git a/common-content/templates/jinja2/blocks/header.en.html b/common-content/templates/jinja2/blocks/en/header.html similarity index 100% rename from common-content/templates/jinja2/blocks/header.en.html rename to common-content/templates/jinja2/blocks/en/header.html diff --git a/common-content/templates/jinja2/blocks/footer.fr.html b/common-content/templates/jinja2/blocks/fr/footer.html similarity index 93% rename from common-content/templates/jinja2/blocks/footer.fr.html rename to common-content/templates/jinja2/blocks/fr/footer.html index 912dacd..ef02da1 100644 --- a/common-content/templates/jinja2/blocks/footer.fr.html +++ b/common-content/templates/jinja2/blocks/fr/footer.html @@ -18,7 +18,7 @@ Accueil
  • - Témoignages clients + Témoignages clients
  • Télécharger la @@ -42,7 +42,7 @@ Gestion de mon compte
  • - Générateur d'enregistrements DNS + Générateur d'enregistrements DNS
  • diff --git a/common-content/templates/jinja2/blocks/header.fr.html b/common-content/templates/jinja2/blocks/fr/header.html similarity index 100% rename from common-content/templates/jinja2/blocks/header.fr.html rename to common-content/templates/jinja2/blocks/fr/header.html diff --git a/content/pages/test/dir/a_page.md b/content/pages/a_page.md similarity index 51% rename from content/pages/test/dir/a_page.md rename to content/pages/a_page.md index 8464a51..d58ec84 100644 --- a/content/pages/test/dir/a_page.md +++ b/content/pages/a_page.md @@ -11,5 +11,5 @@ engine jinja2

    Page 1

    -

    Go to page 2

    +

    Go to page 2

    diff --git a/galae-content/pages/fr-index.md b/content/pages/fr-index.md similarity index 100% rename from galae-content/pages/fr-index.md rename to content/pages/fr-index.md diff --git a/content/templates/jinja2/base.html b/content/templates/jinja2/base.html index 7cf0a0e..adef3d1 100644 --- a/content/templates/jinja2/base.html +++ b/content/templates/jinja2/base.html @@ -30,14 +30,12 @@ {{ block( NAME = "navbar", VERSION = object.metadata.lang|default(""), - DEFAULT_NAME = "navbar.fr.html" ) }}
    {{ block( NAME = "header", VERSION = object.metadata.lang|default(""), - DEFAULT_NAME = "header.fr.html" ) }}
    @@ -48,7 +46,6 @@ {{ block( NAME = "footer", VERSION = object.metadata.lang|default(""), - DEFAULT_NAME = "footer.fr.html" ) }} diff --git a/content/templates/jinja2/blocks/block.html b/content/templates/jinja2/blocks/block.html index d4de33a..d4f47ff 100644 --- a/content/templates/jinja2/blocks/block.html +++ b/content/templates/jinja2/blocks/block.html @@ -3,8 +3,8 @@ {% if VERSION != "" %} {% include [ - "blocks/" + NAME + "." + VERSION + ".html", - "blocks/" + NAME.split('.')[0] + '.' + VERSION + '.' + NAME.split('.')[-1], + "blocks/" + VERSION + '/' + NAME + ".html", + "blocks/" + VERSION + '/' + NAME , "blocks/" + DEFAULT_NAME + ".html", "blocks/" + DEFAULT_NAME ] %} diff --git a/content/templates/jinja2/blocks/navbar.en.html b/content/templates/jinja2/blocks/en/navbar.html similarity index 100% rename from content/templates/jinja2/blocks/navbar.en.html rename to content/templates/jinja2/blocks/en/navbar.html diff --git a/content/templates/jinja2/blocks/navbar.fr.html b/content/templates/jinja2/blocks/fr/navbar.html similarity index 100% rename from content/templates/jinja2/blocks/navbar.fr.html rename to content/templates/jinja2/blocks/fr/navbar.html diff --git a/content/templates/jinja2/image.html b/content/templates/jinja2/image.html deleted file mode 100644 index a3b6c68..0000000 --- a/content/templates/jinja2/image.html +++ /dev/null @@ -1,3 +0,0 @@ - - -{{ VAR3 }} \ No newline at end of file diff --git a/content/templates/jinja2/widgets/navbar.html b/content/templates/jinja2/widgets/navbar.html index f27340c..ed7983c 100644 --- a/content/templates/jinja2/widgets/navbar.html +++ b/content/templates/jinja2/widgets/navbar.html @@ -19,7 +19,7 @@ diff --git a/galae-content/pages/test/another_page.md b/galae-content/pages/another_page.md similarity index 54% rename from galae-content/pages/test/another_page.md rename to galae-content/pages/another_page.md index 78b34fb..0efd582 100644 --- a/galae-content/pages/test/another_page.md +++ b/galae-content/pages/another_page.md @@ -11,4 +11,4 @@ engine jinja2

    Page 2

    -

    Go to page 1

    +

    Go to page 1

    diff --git a/galae-content/pages/en/en-index.md b/galae-content/pages/en-index.md similarity index 100% rename from galae-content/pages/en/en-index.md rename to galae-content/pages/en-index.md diff --git a/galae-content/pages/fr/generateur-enregistrements-dns.md b/galae-content/pages/generateur-enregistrements-dns.md similarity index 100% rename from galae-content/pages/fr/generateur-enregistrements-dns.md rename to galae-content/pages/generateur-enregistrements-dns.md diff --git a/content/pages/fr/temoignages-clients.md b/galae-content/pages/temoignages-clients.md similarity index 100% rename from content/pages/fr/temoignages-clients.md rename to galae-content/pages/temoignages-clients.md diff --git a/jssg/jinja2.py b/jssg/jinja2.py index 131072f..5bea8bb 100644 --- a/jssg/jinja2.py +++ b/jssg/jinja2.py @@ -8,21 +8,12 @@ from jssg.models import Document from django.conf import settings -def url_from_slug(view_name, slug) : - for path in settings.JSSG_PAGES_DIR : - files = path.rglob("*.md") - for f in files : - doc = Document.load(f) - if doc.metadata["slug"] == slug : - return "/" / doc.path.relative_to(path).with_suffix('.html').parent / (doc.metadata["slug"] + ".html") - def environment(**options): env = Environment(**options) env.globals.update( { "static": static, "url": reverse, - "url_slug": url_from_slug, } ) env.filters.update( diff --git a/jssg/models.py b/jssg/models.py index 215661f..a443c32 100644 --- a/jssg/models.py +++ b/jssg/models.py @@ -197,7 +197,7 @@ def load(cls, path: Path) -> "Document": @classmethod def load_glob( - cls, path: Optional[List[Path]] = None, dir = "", glob: str = "*.md", all=False + cls, path: Optional[List[Path]] = None, glob: str = "*.md" ) -> Iterator["Document"]: """Load multiple document. @@ -213,10 +213,7 @@ def load_glob( files = [] for p in path : - if all : - files += (p / dir).rglob(glob) - else : - files += (p / dir).glob(glob) + files += p.glob(glob) print(files) return map(cls.load, files) @@ -239,23 +236,16 @@ def __init__(self, content: str, **metadata) -> None: except KeyError: self.slug = slugify(self.title) - p = self.path - while (p not in self.BASE_DIR) : - p = p.parent - self.dir = str(self.path.relative_to(p).parent) - if self.dir == '.' : - self.dir = '' - @classmethod - def load_page_with_slug(cls, slug: str, dir : str) -> "Page": - return next(filter(lambda p: p.slug == slug, cls.load_glob(dir = dir))) + def load_page_with_slug(cls, slug: str) -> "Page": + return next(filter(lambda p: p.slug == slug, cls.load_glob())) @classmethod def load_glob( - cls, path: Optional[List[Path]] = None, dir = "", glob: str = "*.md", all = False + cls, path: Optional[List[Path]] = None, glob: str = "*.md" ) -> Iterator["Page"]: """Overridden only to make the static typing happy.""" - return super().load_glob(path, dir, glob, all) + return super().load_glob(path, glob) class Post(Page): @@ -272,16 +262,9 @@ def __init__(self, content: str, **metadata) -> None: super().__init__(content, **metadata) self.timestamp = datetime.datetime.fromisoformat(metadata["date"]) - p = self.path - while (p not in self.BASE_DIR) : - p = p.parent - self.dir = str(self.path.relative_to(p).parent) - if self.dir == '.' : - self.dir = '' - @classmethod def load_glob( - cls, path: Optional[List[Path]] = None, dir = "", glob: str = "*.md", all = False + cls, path: Optional[List[Path]] = None, glob: str = "*.md" ) -> Iterator["Post"]: """Overridden only to make the static typing happy.""" - return super().load_glob(path, dir, glob, all) + return super().load_glob(path, glob) diff --git a/jssg/settings.py b/jssg/settings.py index 2c18781..ea8d283 100644 --- a/jssg/settings.py +++ b/jssg/settings.py @@ -43,7 +43,7 @@ # JSSG -JSSG_CONTENT_DIR = [BASE_DIR / "content"] + [Path.home() / "algoo" / "jssg" / "galae-content"] + [Path.home() / "algoo" / "jssg" / "common-content"] +JSSG_CONTENT_DIR = [BASE_DIR / "content"] + [BASE_DIR / "galae-content"] + [BASE_DIR / "common-content"] JSSG_PAGES_DIR = [path / "pages" for path in JSSG_CONTENT_DIR] JSSG_POSTS_DIR = [path / "posts" for path in JSSG_CONTENT_DIR] JSSG_TEMPLATES_DIR = [path / "templates" for path in JSSG_CONTENT_DIR] diff --git a/jssg/urls.py b/jssg/urls.py index bc957e1..033d6f6 100644 --- a/jssg/urls.py +++ b/jssg/urls.py @@ -19,7 +19,7 @@ def get_pages(): - return ({"dir":p.dir, "slug": p.slug} for p in Page.load_glob(all = True)) + return ({"slug": p.slug} for p in Page.load_glob()) def get_posts(): return ({"slug": p.slug} for p in Post.load_glob()) @@ -31,6 +31,12 @@ def get_posts(): distill_path( "", views.IndexView.as_view(), name="index", distill_file="index.html" ), + distill_path( + "pages/.html", + views.PageView.as_view(), + name="page", + distill_func=get_pages, + ), distill_path("atom.xml", views.PostFeedsView(), name="atom_feed"), distill_path( "posts/.html", @@ -38,10 +44,4 @@ def get_posts(): name="post", distill_func=get_posts, ), - distill_re_path( - r'^(?P[a-zA-z0-9-/]*)/(?P[a-zA-z0-9-/]+).html', - views.PageView.as_view(), - name="page", - distill_func=get_pages, - ), ] diff --git a/jssg/views.py b/jssg/views.py index 8986fa1..c9c4a67 100644 --- a/jssg/views.py +++ b/jssg/views.py @@ -51,11 +51,8 @@ class PageView(DetailView): template_name = "page.html" def get_object(self, queryset=None) -> Model: - if "dir" not in self.kwargs.keys() : - self.kwargs["dir"] = "" - print(self.kwargs["dir"]) print(self.kwargs["slug"]) - model = self.model.load_page_with_slug(self.kwargs["slug"], self.kwargs["dir"]) + model = self.model.load_page_with_slug(self.kwargs["slug"]) return model @@ -64,7 +61,6 @@ class IndexView(PageView): template_name = "page.html" def get_object(self, queryset=None) -> Model: - self.kwargs["dir"] = "en" self.kwargs["slug"] = "en-index" return super().get_object(queryset)