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.
|
# External sources.
|
||||||
# If you have blog posts published on medium.com or other 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.
|
# 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:
|
external_sources:
|
||||||
- name: medium.com
|
- name: medium.com
|
||||||
rss_url: https://medium.com/@al-folio/feed
|
rss_url: https://medium.com/@al-folio/feed
|
||||||
|
categories: [external-posts]
|
||||||
|
tags: [medium]
|
||||||
- name: Google Blog
|
- name: Google Blog
|
||||||
posts:
|
posts:
|
||||||
- url: https://blog.google/technology/ai/google-gemini-update-flash-ai-assistant-io-2024/
|
- url: https://blog.google/technology/ai/google-gemini-update-flash-ai-assistant-io-2024/
|
||||||
published_date: 2024-05-14
|
published_date: 2024-05-14
|
||||||
|
categories: [external-posts]
|
||||||
|
tags: [google]
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Newsletter
|
# Newsletter
|
||||||
|
|||||||
@ -42,11 +42,11 @@ module ExternalPosts
|
|||||||
content: e.content,
|
content: e.content,
|
||||||
summary: e.summary,
|
summary: e.summary,
|
||||||
published: e.published
|
published: e.published
|
||||||
})
|
}, src)
|
||||||
end
|
end
|
||||||
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
|
# check if title is composed only of whitespace or foreign characters
|
||||||
if content[:title].gsub(/[^\w]/, '').strip.empty?
|
if content[:title].gsub(/[^\w]/, '').strip.empty?
|
||||||
# use the source name and last url segment as fallback
|
# use the source name and last url segment as fallback
|
||||||
@ -67,6 +67,15 @@ module ExternalPosts
|
|||||||
doc.data['description'] = content[:summary]
|
doc.data['description'] = content[:summary]
|
||||||
doc.data['date'] = content[:published]
|
doc.data['date'] = content[:published]
|
||||||
doc.data['redirect'] = url
|
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]
|
doc.content = content[:content]
|
||||||
site.collections['posts'].docs << doc
|
site.collections['posts'].docs << doc
|
||||||
end
|
end
|
||||||
@ -76,7 +85,7 @@ module ExternalPosts
|
|||||||
puts "...fetching #{post['url']}"
|
puts "...fetching #{post['url']}"
|
||||||
content = fetch_content_from_url(post['url'])
|
content = fetch_content_from_url(post['url'])
|
||||||
content[:published] = parse_published_date(post['published_date'])
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user