Added support for default categories and tags for external posts (#3417)

Based on discussion #3393.

---------

Signed-off-by: George Araújo <george.gcac@gmail.com>
This commit is contained in:
George 2026-01-02 20:37:16 -03:00 committed by GitHub
parent 71640bbda3
commit 81c0556cbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -122,13 +122,18 @@ disqus_shortname: al-folio # put your disqus shortname
# External sources.
# If you have blog posts published on medium.com or other external sources,
# you can display them in your blog by adding a link to the RSS feed.
# Optional: Set default categories and tags for posts from each source.
external_sources:
- name: medium.com
rss_url: https://medium.com/@al-folio/feed
categories: [external-posts]
tags: [medium]
- name: Google Blog
posts:
- url: https://blog.google/technology/ai/google-gemini-update-flash-ai-assistant-io-2024/
published_date: 2024-05-14
categories: [external-posts]
tags: [google]
# -----------------------------------------------------------------------------
# Newsletter

View File

@ -42,11 +42,11 @@ module ExternalPosts
content: e.content,
summary: e.summary,
published: e.published
})
}, src)
end
end
def create_document(site, source_name, url, content)
def create_document(site, source_name, url, content, src = {})
# check if title is composed only of whitespace or foreign characters
if content[:title].gsub(/[^\w]/, '').strip.empty?
# use the source name and last url segment as fallback
@ -67,6 +67,15 @@ module ExternalPosts
doc.data['description'] = content[:summary]
doc.data['date'] = content[:published]
doc.data['redirect'] = url
# Apply default categories and tags from source configuration
if src['categories'] && src['categories'].is_a?(Array) && !src['categories'].empty?
doc.data['categories'] = src['categories']
end
if src['tags'] && src['tags'].is_a?(Array) && !src['tags'].empty?
doc.data['tags'] = src['tags']
end
doc.content = content[:content]
site.collections['posts'].docs << doc
end
@ -76,7 +85,7 @@ module ExternalPosts
puts "...fetching #{post['url']}"
content = fetch_content_from_url(post['url'])
content[:published] = parse_published_date(post['published_date'])
create_document(site, src['name'], post['url'], content)
create_document(site, src['name'], post['url'], content, src)
end
end