Skip to content

Instantly share code, notes, and snippets.

@jorgemanrubia
Created January 25, 2023 08:39
Show Gist options
  • Save jorgemanrubia/03d08ca10ab3816885bc87c87ecfee23 to your computer and use it in GitHub Desktop.
Save jorgemanrubia/03d08ca10ab3816885bc87c87ecfee23 to your computer and use it in GitHub Desktop.
Script I use to sync my HEY World posts with my Jekyll-powered personal site
require "rss"
require "ostruct"
RSS_FEED_URL = "https://world.hey.com/jorge/feed.atom"
def sync_posts
feed = RSS::Parser.parse(RSS_FEED_URL, false)
feed.items.each do |item|
post = OpenStruct.new title: item.title.content, date: item.published.content.strftime("%Y-%m-%d"), link: item.link.href
sync_post post
end
end
def sync_post(post)
file_name = file_name_for(post)
file_path = "../_posts/#{file_name}"
unless File.exists?(file_path)
puts "Syncing #{file_name}..."
File.open(file_path, "w") { |file| file.write content_for(post) }
end
end
def file_name_for(post)
slug = post.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
"#{post.date}-#{slug}.md"
end
def content_for(post)
<<~MD
---
title: #{post.title.gsub(":", "&#58;")}
layout: post
external_url: #{post.link}
---
MD
end
sync_posts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment