From 8b99f0b55e2cddedd20e7874a63d98dd0e95c592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Fri, 12 Jul 2024 16:06:57 +0200 Subject: [PATCH] change the slug url format in url_for_slug_path() from /folder/test/file.html to /folder/test/file --- content/templates/jinja2/blocks/en/navbar.html | 2 +- content/templates/jinja2/blocks/fr/navbar.html | 2 +- jssg/jinja2.py | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/content/templates/jinja2/blocks/en/navbar.html b/content/templates/jinja2/blocks/en/navbar.html index 80f83a1..1793de7 100644 --- a/content/templates/jinja2/blocks/en/navbar.html +++ b/content/templates/jinja2/blocks/en/navbar.html @@ -4,7 +4,7 @@ CTA_LABEL="See pricing", CTA_TARGET="", CTA_URL="#pricing", - CHANGE_LANG_URL="/fr-index.html", + 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/fr/navbar.html b/content/templates/jinja2/blocks/fr/navbar.html index 7f48327..1baace1 100644 --- a/content/templates/jinja2/blocks/fr/navbar.html +++ b/content/templates/jinja2/blocks/fr/navbar.html @@ -4,7 +4,7 @@ CTA_LABEL="Découvrir les tarifs", CTA_TARGET="", CTA_URL="#pricing", - CHANGE_LANG_URL="/en-index.html", + 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/jssg/jinja2.py b/jssg/jinja2.py index f8ad0ca..dcbbf73 100644 --- a/jssg/jinja2.py +++ b/jssg/jinja2.py @@ -53,34 +53,35 @@ def url_for_slug(slug) : def url_for_slug_path(url_path) : """ @param url_path: the url of the page to search (absolute path) - @return: the string of the url corresponding to the page + @return: the string of the slug url corresponding to the page @error: raise an exception if the url is a dead link - >>> url_for_slug_path('/en/index.html') # the page exists + >>> url_for_slug_path('/en/index') # the page exists /en/index.html - >>> url_for_slug_path('/en/index-removed.html') # the page does not exist + >>> url_for_slug_path('/en/index-removed') # the page does not exist Traceback (most recent call last): ... - Exception: page for '/en/index-removed.html' url not found (dead link) + Exception: page for '/en/index-removed' url not found (dead link) >>> url_for_slug_path('folder/index') Traceback (most recent call last): ... - Exception: url 'folder/index' is not valid ; correct urls are //.html or / + Exception: url 'folder/index' is not valid ; correct urls are // or / """ # Valid url are //.html or /.html # Example: if url_path is "/tmp/folder/subfolder/thefile.html", then slug will be "thefile" and the dir will be "tmp/folder/subfolder" + # Note : the dir does not start with '/' since the url parsed in url.py do not either try : - _, dir, slug = re.findall(r"(^|^/([a-zA-Z0-9-/]+))/([a-zA-Z0-9-]+)\.html", url_path)[0] + _, dir, slug = re.findall(r"(^|^/([a-zA-Z0-9/-]+))/([a-zA-Z0-9-]+)$", url_path)[0] except : - raise Exception("url '%s' is not valid ; correct urls are //.html or /.html" % url_path) + raise Exception("url '%s' is not valid ; correct urls are // or /" % url_path) # Verify that the page exists for page in Page.load_glob(all=True) : if page.slug == slug and page.rel_folder_path == dir : - return url_path + return url_path + ".html" raise Exception("page for '%s' url not found (dead link)" % url_path)