diff --git a/common-content/templates/jinja2/blocks/footer.en.html b/common-content/templates/jinja2/blocks/footer.en.html
index b6d4ccb..40cdc32 100644
--- a/common-content/templates/jinja2/blocks/footer.en.html
+++ b/common-content/templates/jinja2/blocks/footer.en.html
@@ -15,7 +15,7 @@
-
- Home
+ Home
-
Customer testimonials (FR)
diff --git a/common-content/templates/jinja2/blocks/footer.fr.html b/common-content/templates/jinja2/blocks/footer.fr.html
index 97c4ebf..8f5721c 100644
--- a/common-content/templates/jinja2/blocks/footer.fr.html
+++ b/common-content/templates/jinja2/blocks/footer.fr.html
@@ -15,7 +15,7 @@
-
- Accueil
+ Accueil
-
Témoignages clients
diff --git a/content/templates/jinja2/blocks/navbar.en.html b/content/templates/jinja2/blocks/navbar.en.html
index d2ddb7b..57e971e 100644
--- a/content/templates/jinja2/blocks/navbar.en.html
+++ b/content/templates/jinja2/blocks/navbar.en.html
@@ -4,7 +4,7 @@
CTA_LABEL="See pricing",
CTA_TARGET="",
CTA_URL="#pricing",
- CHANGE_LANG_URL="fr-index",
+ CHANGE_LANG_URL="fr/index",
CHANGE_LANG_FLAG_URL="assets/img/lang-fr.svg",
CHANGE_LANG_ALT="Version française"
) }}
\ No newline at end of file
diff --git a/content/templates/jinja2/blocks/navbar.fr.html b/content/templates/jinja2/blocks/navbar.fr.html
index 29345f5..7d74690 100644
--- a/content/templates/jinja2/blocks/navbar.fr.html
+++ b/content/templates/jinja2/blocks/navbar.fr.html
@@ -4,7 +4,7 @@
CTA_LABEL="Découvrir les tarifs",
CTA_TARGET="",
CTA_URL="#pricing",
- CHANGE_LANG_URL="en-index",
+ CHANGE_LANG_URL="en/index",
CHANGE_LANG_FLAG_URL="assets/img/lang-gb.svg",
CHANGE_LANG_ALT="English version"
) }}
\ No newline at end of file
diff --git a/content/templates/jinja2/widgets/navbar.html b/content/templates/jinja2/widgets/navbar.html
index 360b881..445d1dc 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/en/en-index.md b/galae-content/pages/en/en-index.md
index 4e751d7..4f47b20 100644
--- a/galae-content/pages/en/en-index.md
+++ b/galae-content/pages/en/en-index.md
@@ -1,6 +1,6 @@
--- METADATA (first) ---
title galae - ethical and free pay-per-use e-mail
-slug en-index
+slug index
description galae est un service e-mail éthique et libre facturé à l'usage. Toutes nos offres incluent des boîtes emails et domaines illimités hébergés en France.
language French
lang en
diff --git a/galae-content/pages/fr-index.md b/galae-content/pages/fr/fr-index.md
similarity index 99%
rename from galae-content/pages/fr-index.md
rename to galae-content/pages/fr/fr-index.md
index c40d75c..b85e816 100644
--- a/galae-content/pages/fr-index.md
+++ b/galae-content/pages/fr/fr-index.md
@@ -1,6 +1,6 @@
--- METADATA (first) ---
title galae - le service e-mail éthique et libre facturé à l'usage
-slug fr-index
+slug index
description galae est un service e-mail éthique et libre facturé à l'usage. Toutes nos offres incluent des boîtes emails et domaines illimités hébergés en France.
language French
lang fr
diff --git a/jssg/jinja2.py b/jssg/jinja2.py
index e5e4ec2..ee4fea9 100644
--- a/jssg/jinja2.py
+++ b/jssg/jinja2.py
@@ -5,17 +5,37 @@
from jssg.templatetags.filter_opengraph_metadata import filter_opengraph_metadata
-from jssg.models import Document
-from django.conf import settings
+from jssg.models import Page
def url_from_slug(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")
- return ""
+ url = ""
+ pages_with_slug = ""
+
+ for page in Page.load_glob(all=True) :
+ if page.slug == slug :
+ if pages_with_slug == "" :
+ url = "/" + page.dir + "/" + page.slug + ".html"
+ else :
+ url = ""
+ pages_with_slug += str(page.path.relative_to(page.page_dir.parent)) + ", "
+
+ if url == "" and pages_with_slug != "" :
+ raise Exception("url_slug() : slug '%s' is not unique, found in : [%s] ; use url_abs()" % (slug, pages_with_slug[:-2]))
+ elif url == "" :
+ raise Exception("url_slug() : slug '%s' not found" % slug)
+ return url
+
+def url_absolute(url_path) :
+ dir = '/'.join(url_path.split('/')[:-1])
+ slug = ''.join((''.join(url_path.split('/')[-1])).split('.')[0])
+
+ for page in Page.get_pages() :
+ if page["slug"] == slug and dir == "" :
+ return "/" + slug + ".html"
+ elif page["slug"] == slug and "dir" in page.keys() and page["dir"] == dir :
+ return "/" + dir + "/" + slug + ".html"
+
+ raise Exception("url_abs() : page for %s url not found" % url_path)
def environment(**options):
env = Environment(**options)
@@ -24,6 +44,7 @@ def environment(**options):
"static": static,
"url": reverse,
"url_slug": url_from_slug,
+ "url_abs" : url_absolute
}
)
env.filters.update(
diff --git a/jssg/models.py b/jssg/models.py
index 215661f..faaa432 100644
--- a/jssg/models.py
+++ b/jssg/models.py
@@ -239,10 +239,11 @@ 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)
+ self.page_dir = self.path
+ while (self.page_dir not in self.BASE_DIR) :
+ self.page_dir = self.page_dir.parent
+
+ self.dir = str(self.path.relative_to(self.page_dir).parent)
if self.dir == '.' :
self.dir = ''
@@ -256,6 +257,10 @@ def load_glob(
) -> Iterator["Page"]:
"""Overridden only to make the static typing happy."""
return super().load_glob(path, dir, glob, all)
+
+ @classmethod
+ def get_pages(cls) :
+ return ({"slug": p.slug} if p.dir == '' else {"dir": p.dir, "slug" : p.slug} for p in Page.load_glob(all = True))
class Post(Page):
@@ -272,16 +277,13 @@ 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
) -> Iterator["Post"]:
"""Overridden only to make the static typing happy."""
return super().load_glob(path, dir, glob, all)
+
+ @classmethod
+ def get_posts(cls) :
+ return ({"slug": p.slug} if p.dir == '' else {"dir": p.dir, "slug" : p.slug} for p in Post.load_glob(all = True))
diff --git a/jssg/urls.py b/jssg/urls.py
index f012595..234429e 100644
--- a/jssg/urls.py
+++ b/jssg/urls.py
@@ -18,13 +18,8 @@
from jssg.models import Page, Post
from jssg import settings
-def get_pages() :
- return ({"slug": p.slug} if p.dir == '' else {"dir": p.dir, "slug" : p.slug} for p in Page.load_glob(all = True))
-def get_posts() :
- return ({"slug": p.slug} if p.dir == '' else {"dir": p.dir, "slug" : p.slug} for p in Post.load_glob(all = True))
-
-print([p for p in get_pages()])
+# print([p for p in Page.get_pages()])
urlpatterns = [
distill_path(
@@ -35,24 +30,24 @@ def get_posts() :
r'^(?!posts/)(?P[a-zA-Z0-9-]+).html$',
views.PageView.as_view(),
name="page",
- distill_func=get_pages,
+ distill_func=Page.get_pages,
),
distill_re_path(
r'^(?!posts/)(?P[a-zA-Z-/]+)/(?P[a-zA-Z0-9-]+).html$',
views.PageView.as_view(),
name="page",
- distill_func=get_pages,
+ distill_func=Page.get_pages,
),
distill_path(
"posts/.html",
views.PostView.as_view(),
name="post",
- distill_func=get_posts,
+ distill_func=Post.get_posts,
),
distill_path(
"posts//.html",
views.PostView.as_view(),
name="post",
- distill_func=get_posts,
+ distill_func=Post.get_posts,
)
]
diff --git a/jssg/views.py b/jssg/views.py
index e4cfd8e..fdc86b7 100644
--- a/jssg/views.py
+++ b/jssg/views.py
@@ -65,7 +65,7 @@ class IndexView(PageView):
def get_object(self, queryset=None) -> Model:
self.kwargs["dir"] = "en"
- self.kwargs["slug"] = "en-index"
+ self.kwargs["slug"] = "index"
return super().get_object(queryset)