Created
January 25, 2023 08:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(":", ":")} | |
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