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:
parent
71640bbda3
commit
81c0556cbf
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user