[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[www] 12/19: inc: more logic to remove code from Makefile. news/index.hm
From: |
gnunet |
Subject: |
[www] 12/19: inc: more logic to remove code from Makefile. news/index.hmtl.j2: syntax. |
Date: |
Wed, 13 Nov 2019 01:28:44 +0100 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository www.
commit ab19fc81090ebbbecf471b010bc41f5a43ec858f
Author: ng0 <address@hidden>
AuthorDate: Tue Nov 12 21:30:39 2019 +0000
inc: more logic to remove code from Makefile. news/index.hmtl.j2: syntax.
---
GNUmakefile | 2 +-
Makefile | 8 ++++----
inc/fileproc.py | 13 +++++++++++++
inc/i18nfix.py | 2 +-
inc/site.py | 50 ++++++++++++++++++++++++++++++++++++++------------
inc/sitemap.py | 1 +
inc/sum.py | 2 --
inc/textproc.py | 8 ++++++--
make_site.py | 33 +++++++++++++++++++++++++++------
news/index.html.j2 | 2 +-
10 files changed, 92 insertions(+), 29 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index d29a6d4..4dc2b72 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -28,7 +28,7 @@ all: css locale template
(for lang in en de es fr it ; do \
$(cp) rendered/static/robots.txt rendered/$$lang/robots.txt ; \
done)
- ($(cp) favicon.ico rendered/favicon.ico)
+ #($(cp) favicon.ico rendered/favicon.ico)
($(sh) make_sitemap.sh)
($(cp) rendered/sitemap.xml rendered/en/sitemap.xml)
($(cp) static/moved.html rendered/frontpage.html)
diff --git a/Makefile b/Makefile
index 73bcb3d..9c78465 100644
--- a/Makefile
+++ b/Makefile
@@ -21,9 +21,9 @@ _DIRLIST= dist static
# All: build HTML pages in all languages and compile the
# TypeScript logic in web-common.
all: css locale template
-.for _dir in ${_DIRLIST}
- $(cp) -R ${_dir} rendered/
-.endfor
+#.for _dir in ${_DIRLIST}
+# $(cp) -R ${_dir} rendered/
+#.endfor
.for _lang in ${_LOCALELIST}
($(cp) rendered/static/robots.txt rendered/${_lang})
($(cp) rendered/static/stage.robots.txt rendered/${_lang})
@@ -74,7 +74,7 @@ locale: locale-update locale-compile
# Run the jinja2 templating engine to expand templates to HTML
# incorporating translations.
template: locale-compile
- $(python) ./make_site.py
+ $(python) ./make_site.py -vvvv
css:
$(sassc) static/styles.sass static/styles.css
diff --git a/inc/fileproc.py b/inc/fileproc.py
index 435078b..bf6cc8d 100644
--- a/inc/fileproc.py
+++ b/inc/fileproc.py
@@ -1,4 +1,17 @@
from pathlib import Path
+import os
+import shutil
+
+def copy_tree(source, destination):
+ destination.mkdir(parents=True, exist_ok=True)
+ for _ in os.listdir(source):
+ i = source / _
+ o = destination / _
+ if i.is_dir():
+ copy_tree(i, o)
+ else:
+ shutil.copy2(str(i), str(o))
+
def copy_files(kind, conf, locale, inlist, ptarget):
o = Path(ptarget)
diff --git a/inc/i18nfix.py b/inc/i18nfix.py
index 7f326ba..69fe177 100644
--- a/inc/i18nfix.py
+++ b/inc/i18nfix.py
@@ -6,7 +6,6 @@
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
-
"""
Extract translations from a Jinja2 template, stripping leading newlines.
@@ -38,4 +37,5 @@ def wrap_gettext(f):
def wrapper(message):
message = normalize(message)
return f(message)
+
return wrapper
diff --git a/inc/site.py b/inc/site.py
index 67e5afa..9fd9ac8 100644
--- a/inc/site.py
+++ b/inc/site.py
@@ -6,29 +6,51 @@ import gettext
import glob
import codecs
import jinja2
-import hashlib
-from pathlib import Path, PurePosixPath
+from pathlib import Path, PurePosixPath, PurePath
from ruamel.yaml import YAML
-import inc.i18nfix
+import inc.i18nfix as i18nfix
from inc.textproc import cut_news_text
-from inc.fileproc import copy_files
+from inc.fileproc import copy_files, copy_tree
class gen_site:
+ def __init__(self, debug):
+ self.debug = debug
+
def load_config(self, name="www.yml"):
yaml = YAML(typ='safe')
site_configfile = Path(name)
return yaml.load(site_configfile)
+ def copy_trees(self, directory):
+ """ Take a directory name (string) and pass it to copy_tree() as Path
object. """
+ i = Path(directory)
+ o = Path("rendered/" + directory)
+ copy_tree(i, o)
+
def gen_abstract(self, conf, name, member, pages, length):
+ if self.debug:
+ print("generating abstracts...")
for item in conf[name]:
item[member] = cut_news_text(item[pages], length)
+ if self.debug:
+ print("cwd: " + str(Path.cwd()))
+ if self.debug > 1:
+ print(conf["newsposts"])
+ if self.debug:
+ print("[done] generating abstracts")
def run(self, root, conf, env):
- # os.chdir("..")
- print(os.getcwd())
- root = "../" + root
- for in_file in glob.glob(root + "/*.j2"):
+ # root = "../" + root
+ if self.debug:
+ _ = Path(".")
+ q = list(_.glob("**/*.j2"))
+ print(q)
+ # for in_file in glob.glob(root + "/*.j2"):
+ for in_file in Path(".").glob(root + "/*.j2"):
+ in_file = str(in_file)
+ if self.debug:
+ print(in_file)
name, ext = re.match(r"(.*)\.([^.]+)$",
in_file.rstrip(".j2")).groups()
tmpl = env.get_template(in_file)
@@ -74,8 +96,14 @@ class gen_site:
# return "../" + x
return "../" + x
- for l in glob.glob("locale/*/"):
- locale = os.path.basename(l[:-1])
+ # for l in glob.glob("locale/*/"):
+ # https://bugs.python.org/issue22276
+ for l in list(x for x in Path(".").glob("locale/*/") if
x.is_dir()):
+ l = str(PurePath(l).name)
+ if self.debug:
+ print(l)
+ # locale = os.path.basename(l[:-1])
+ locale = l
tr = gettext.translation("messages",
localedir="locale",
@@ -106,8 +134,6 @@ class gen_site:
root + '/', '').rstrip(".j2")
outdir = Path("rendered")
- if outdir.exists() is False:
- sys.exit(1)
if root == "news":
langdir = outdir / locale / root
diff --git a/inc/sitemap.py b/inc/sitemap.py
index e050c77..5ccf744 100644
--- a/inc/sitemap.py
+++ b/inc/sitemap.py
@@ -1,6 +1,7 @@
import os
from pathlib import Path, PurePosixPath
+
def sitemap_tree(path):
tree = dict(name=PurePosixPath(path).name, children=[])
try:
diff --git a/inc/sum.py b/inc/sum.py
index 9addf78..fff7a81 100644
--- a/inc/sum.py
+++ b/inc/sum.py
@@ -31,5 +31,3 @@ def walksum(_):
traceback.print_exc()
return -2
return sha256.hexdigest()
-
-
diff --git a/inc/textproc.py b/inc/textproc.py
index 228518b..f3b97d3 100644
--- a/inc/textproc.py
+++ b/inc/textproc.py
@@ -1,12 +1,15 @@
import html.parser
from bs4 import BeautifulSoup
+
class extractText(html.parser.HTMLParser):
def __init__(self):
super(extractText, self).__init__()
self.result = []
+
def handle_data(self, data):
self.result.append(data)
+
def text_in(self):
return ''.join(self.result)
@@ -27,8 +30,9 @@ def cut_text(filename, count):
k.append(i)
b = ''.join(str(e) for e in k)
text = html2text(b.replace("\n", ""))
- textreduced = (text[:count] + '...') if len(text) > count else (text +
'..')
- return(textreduced)
+ textreduced = (text[:count] + '...') if len(text) > count else (text +
+ '..')
+ return (textreduced)
def cut_news_text(filename, count):
diff --git a/make_site.py b/make_site.py
index c4a17e2..d335f97 100755
--- a/make_site.py
+++ b/make_site.py
@@ -18,29 +18,50 @@
# is thus to be invoked via the Makefile.
import jinja2
-import os
+import sys
+from pathlib import Path, PurePath
from inc.site import gen_site
from inc.fileproc import copy_files
-env =
jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__),"inc"),
+env =
jinja2.Environment(loader=jinja2.FileSystemLoader(str(PurePath(__file__).parent)),
extensions=["jinja2.ext.i18n"],
lstrip_blocks=True,
trim_blocks=True,
undefined=jinja2.StrictUndefined,
autoescape=False)
+if len(sys.argv) >= 2 and sys.argv[1] == "-vv":
+ DEBUG=1
+elif len(sys.argv) >= 2 and sys.argv[1] == "-vvv":
+ DEBUG=2
+elif len(sys.argv) >= 2 and sys.argv[1] == "-vvvv":
+ DEBUG=3
+else:
+ DEBUG=0
+
def main():
# rm_rf("rendered")
- x = gen_site()
+ x = gen_site(DEBUG)
conf = x.load_config("www.yml")
- print("generating news abstracts...")
x.gen_abstract(conf, "newsposts", "abstract", "page", 1000)
- print("generating html from jinja2 templates...")
+ if DEBUG:
+ print("generating html from jinja2 templates...")
x.run("template", conf, env)
- print("generating html from jinja2 news templates...")
+ if DEBUG:
+ print(Path.cwd())
+ _ = Path("rendered")
+ for child in _.iterdir():
+ print(child)
+ if DEBUG:
+ print(Path.cwd())
+ print("generating html from jinja2 news templates...")
x.run("news", conf, env)
#for lang in conf["langs_full"]:
# copy_files("static", conf, lang, "staticfiles", "rendered")
+ if DEBUG:
+ print("copying directories...")
+ x.copy_trees("static")
+ x.copy_trees("dist")
# print("generating rss...")
# x.generate_rss()
# print("generating sitemap...")
diff --git a/news/index.html.j2 b/news/index.html.j2
index 8c58d9f..bdb716d 100644
--- a/news/index.html.j2
+++ b/news/index.html.j2
@@ -10,7 +10,7 @@
<section>
<p>
News posts published by GNUnet about changes related to
- GNUnet, releases, and events.
+ GNUnet, releases, and events – <a href="{{
url_localized('rss.xml')}}">subscribe to our RSS feed</a>
</p>
</section>
</div>
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [www] 02/19: rm old templates folder., (continued)
- [www] 02/19: rm old templates folder., gnunet, 2019/11/12
- [www] 01/19: drop guix-env.scm, no longer maintained., gnunet, 2019/11/12
- [www] 06/19: remove FIXME., gnunet, 2019/11/12
- [www] 09/19: move jinja2 ext to inc., gnunet, 2019/11/12
- [www] 07/19: remove taler flyer, leftover from initial base., gnunet, 2019/11/12
- [www] 15/19: build-system, gnunet, 2019/11/12
- [www] 14/19: add submodule for www_shared -> inc., gnunet, 2019/11/12
- [www] 08/19: minor syntax fixes in engage., gnunet, 2019/11/12
- [www] 16/19: inc, new commits, gnunet, 2019/11/12
- [www] 13/19: move inc to www_shared repo, gnunet, 2019/11/12
- [www] 12/19: inc: more logic to remove code from Makefile. news/index.hmtl.j2: syntax.,
gnunet <=
- [www] 10/19: split up template.py, make site generation a class., gnunet, 2019/11/12
- [www] 17/19: use make_sitemap.py, gnunet, 2019/11/12
- [www] 19/19: make build more silent again., gnunet, 2019/11/12
- [www] 18/19: inc, gnunet, 2019/11/12
- [www] 11/19: rename template.py to make_site.py, gnunet, 2019/11/12