diff --git a/lumbunglib/feed.py b/lumbunglib/feed.py index 1e25fdc..4113e52 100644 --- a/lumbunglib/feed.py +++ b/lumbunglib/feed.py @@ -85,6 +85,11 @@ def create_frontmatter(entry): for t in entry.tags: tags.append(t['term']) + if "featured_image" in entry: + featured_image = entry.featured_image + else: + featured_image = '' + card_type = "network" if entry.feed_name == "pen.lumbung.space": card_type = "pen" @@ -110,7 +115,8 @@ def create_frontmatter(entry): 'original_link': entry.link, 'feed_name': entry['feed_name'], 'tags': str(tags), - 'card_type': card_type + 'card_type': card_type, + 'featured_image': featured_image } return frontmatter @@ -136,11 +142,30 @@ def sanitize_yaml (frontmatter): return frontmatter +def parse_enclosures(post_dir, entry): + """ + Parses feed enclosures which are featured media + Can be featured image but also podcast entries + https://pythonhosted.org/feedparser/reference-entry-enclosures.html + """ + #TODO parse more than images + #TODO handle the fact it could be multiple items + + for e in entry.enclosures: + print("found enclosed media", e.type) + if "image/" in e.type: + featured_image = grab_media(post_dir, e.href) + entry["featured_image"] = featured_image + return entry + def create_post(post_dir, entry): """ write hugo post based on RSS entry """ + if "enclosures" in entry: + entry = parse_enclosures(post_dir, entry) + frontmatter = create_frontmatter(entry) if not os.path.exists(post_dir): @@ -202,6 +227,7 @@ def parse_posts(post_dir, post_content): for img in soup(["img", "object"]): if img.get("src") != None: + local_image = grab_media(post_dir, img["src"]) if img["src"] != local_image: img["src"] = local_image diff --git a/lumbunglib/templates/feed.md b/lumbunglib/templates/feed.md index d9f3f9a..71d984b 100644 --- a/lumbunglib/templates/feed.md +++ b/lumbunglib/templates/feed.md @@ -8,6 +8,7 @@ original_link: "{{ frontmatter.original_link }}" feed_name: "{{ frontmatter.feed_name}}" categories: ["{{ frontmatter.card_type }}", "{{ frontmatter.feed_name}}"] tags: {{ frontmatter.tags }} +{% if frontmatter.featured_image %}featured_image: "{{frontmatter.featured_image}}"{% endif %} --- {{ content }}