You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by wa...@apache.org on 2021/06/07 18:33:58 UTC

[openwebbeans-site] 02/16: Add blog content retrieval

This is an automated email from the ASF dual-hosted git repository.

wave pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans-site.git

commit 65fad73d544688dc12e967ccd893e4b6028b1c0c
Author: Dave Fisher <da...@davefisher.tech>
AuthorDate: Mon Jun 7 09:07:19 2021 -0700

    Add blog content retrieval
---
 asfdata.yaml             |  1 +
 theme/plugins/asfdata.py | 18 ++++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/asfdata.yaml b/asfdata.yaml
index ff08d7b..353de53 100644
--- a/asfdata.yaml
+++ b/asfdata.yaml
@@ -6,4 +6,5 @@ owb:
   # load, transform, and create a sequence of owb blogs
   blog: https://blogs.apache.org/owb/feed/entries/atom
   count: 3
+  content: 40
 
diff --git a/theme/plugins/asfdata.py b/theme/plugins/asfdata.py
index 89b48c2..54dffab 100644
--- a/theme/plugins/asfdata.py
+++ b/theme/plugins/asfdata.py
@@ -346,7 +346,7 @@ def get_element_text(entry, child):
 
 
 # retrieve blog posts from an Atom feed.
-def process_blog(feed, count, debug):
+def process_blog(feed, count, words, debug):
     print(f'blog feed: {feed}')
     content = requests.get(feed).text
     dom = xml.dom.minidom.parseString(content)
@@ -358,11 +358,16 @@ def process_blog(feed, count, debug):
     for entry in entries:
         if debug:
             print(entry.tagName)
-        # we only want the title and href
+        # we may want content
+        content_text = ''
+        if words:
+            content_text = get_element_text(entry, 'content').split(' ')[:words].join(' ') + "..."
+        # we want the title and href
         v.append(
             {
                 'id': get_element_text(entry, 'id'),
                 'title': get_element_text(entry, 'title'),
+                'content': content_text
             }
         )
     if debug:
@@ -370,7 +375,8 @@ def process_blog(feed, count, debug):
             print(s)
 
     return [ Blog(href=s['id'],
-                  title=s['title'])
+                  title=s['title'],
+                  content=s['content'])
              for s in v ]
 
 
@@ -525,7 +531,11 @@ def config_read_data(pel_ob):
                     # process blog feed
                     feed = config_data[key]['blog']
                     count = config_data[key]['count']
-                    metadata[key] = v = process_blog(feed, count, debug)
+                    if config_data[key]['content']:
+                        words = config_data[key]['content']
+                    else:
+                        words = None
+                    metadata[key] = v = process_blog(feed, count, words, debug)
                     if debug:
                         print('BLOG V:', v)
                     continue