diff --git a/_config.yml b/_config.yml index 01c3d23..f733b34 100644 --- a/_config.yml +++ b/_config.yml @@ -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 diff --git a/_plugins/external-posts.rb b/_plugins/external-posts.rb index de812e6..c43aec5 100644 --- a/_plugins/external-posts.rb +++ b/_plugins/external-posts.rb @@ -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