[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[www_shared] 01/02: make localized self URLs absolute
From: |
gnunet |
Subject: |
[www_shared] 01/02: make localized self URLs absolute |
Date: |
Tue, 04 May 2021 22:03:50 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository www_shared.
commit 9f19bf98677b7e99fccad018c7d76710e6417e63
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue May 4 21:53:30 2021 +0200
make localized self URLs absolute
---
site.py | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/site.py b/site.py
index 344a493..71095f8 100644
--- a/site.py
+++ b/site.py
@@ -36,7 +36,7 @@ from inc.textproc import cut_news_text, cut_article
from inc.fileproc import copy_files, copy_tree
from inc.make_rss import *
-class gen_site:
+class SiteGenerator:
def __init__(self, debug):
self.debug = debug
@@ -84,7 +84,8 @@ class gen_site:
_ = Path(".")
q = list(_.glob("**/*.j2"))
print(q)
- # for in_file in glob.glob(root + "/*.j2"):
+ abs_cwd = Path(".").resolve()
+
for in_file in Path(".").glob(root + "/*.j2"):
in_file = str(in_file)
if self.debug > 1:
@@ -93,16 +94,22 @@ class gen_site:
in_file.rstrip(".j2")).groups()
tmpl = env.get_template(in_file)
- def self_localized(other_locale):
+ def self_localized(other_locale, relative=False):
"""
Return URL for the current page in another locale.
"""
- if root == "news":
- return "../../" + other_locale + "/news/" +
in_file.replace(
- root + '/', '').rstrip(".j2")
+ abs_file = Path(in_file).resolve()
+ baseurl = os.environ.get("BASEURL")
+ if relative or not baseurl:
+ if root == "news":
+ return "../../" + other_locale + "/news/" +
in_file.replace(
+ root + '/', '').rstrip(".j2")
+ else:
+ return "../" + other_locale + "/" + in_file.replace(
+ root + '/', '').rstrip(".j2")
else:
- return "../" + other_locale + "/" + in_file.replace(
- root + '/', '').rstrip(".j2")
+ return baseurl + other_locale + "/" +
str(Path(abs_file).relative_to(abs_cwd)).rstrip(".j2")
+
def url_localized(filename):
if root == "news":
@@ -147,7 +154,6 @@ class gen_site:
# locale = os.path.basename(l[:-1])
locale = l
-
try:
tr = gettext.translation("messages",
localedir="locale",
@@ -203,5 +209,9 @@ class gen_site:
if self.debug > 1:
print(Path.cwd())
f.write(content)
- except e as Error:
+ except:
print(e)
+
+# Deprecated alias. Should be removed once all sites have
+# been updated.
+gen_site = SiteGenerator
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.