gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[www_shared] branch master updated: implement body extraction filter


From: gnunet
Subject: [www_shared] branch master updated: implement body extraction filter
Date: Tue, 11 May 2021 18:49:36 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository www_shared.

The following commit(s) were added to refs/heads/master by this push:
     new ebfd9c6  implement body extraction filter
ebfd9c6 is described below

commit ebfd9c60d0e59f6373309ac96d8abf6094ceefb9
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue May 11 18:45:51 2021 +0200

    implement body extraction filter
---
 sitegen/site.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sitegen/site.py b/sitegen/site.py
index 1767a2a..f9d3e7d 100644
--- a/sitegen/site.py
+++ b/sitegen/site.py
@@ -65,6 +65,16 @@ def cut_text(filename, count):
         return textreduced
 
 
+def extract_body(text):
+    """Extract the body of some HTML and
+    return it wrapped in an <article> tag."""
+    soup = BeautifulSoup(text, features="lxml")
+    bs = soup.findAll("body")
+    b = bs[0]
+    b.name = "article"
+    return b.prettify()
+
+
 def make_helpers(root, in_file, locale):
     """Return a dictionary of helpers that should be available in
     the template."""
@@ -182,6 +192,7 @@ class SiteGenerator:
             undefined=jinja2.StrictUndefined,
             autoescape=False,
         )
+        env.filters["extract_body"] = extract_body
         env.newstyle_gettext = True
         self.env = env
         yaml = YAML(typ="safe")

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]