diff options
author | Bradley Taunt <bt@btxx.org> | 2024-07-23 13:13:21 -0400 |
---|---|---|
committer | Bradley Taunt <bt@btxx.org> | 2024-07-23 13:13:21 -0400 |
commit | d6dedf8c13eeb10998c2dcc930e7965c136ec338 (patch) | |
tree | d7d64e18624f4b736b00f86c6a5898cc8671518d | |
parent | a589410d964ee27733fb1c99a25e619e8c80b310 (diff) |
Testing fix for odd UTC date format in RSS
-rw-r--r-- | wruby.rb | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -45,6 +45,16 @@ def extract_title_from_md(lines) first_line&.start_with?('# ') ? first_line[2..-1].strip : 'Blog Index' end +# Grab the date from each markdown file +def extract_date_from_md(lines) + date_str = lines[2]&.strip + begin + date_str ? DateTime.parse(date_str).new_offset(0) : DateTime.now.new_offset(0) + rescue Date::Error + DateTime.now.new_offset(0) + end +end + # Convert markdown files def process_markdown_files(input_directory, output_directory, header_content, footer_content) items = [] @@ -56,7 +66,7 @@ def process_markdown_files(input_directory, output_directory, header_content, fo lines = md_content.lines title = extract_title_from_md(lines) - date = Date.parse(lines[2]&.strip || '') rescue Date.today + date = extract_date_from_md(lines) html_content = Kramdown::Document.new(md_content).to_html relative_path = path.sub(input_directory + '/', '').sub('.md', '') @@ -113,7 +123,7 @@ def generate_rss(posts, rss_file, author_name, site_name, site_url, posts_dir) maker.channel.link = site_url posts.each do |post| - date = DateTime.parse(post[:date].to_s).to_time.utc + date = DateTime.parse(post[:date].to_s).new_offset('-05:00') item_link = "#{site_url}/#{posts_dir}/#{post[:link]}" item_title = post[:title] item_content = post[:content] @@ -121,8 +131,8 @@ def generate_rss(posts, rss_file, author_name, site_name, site_url, posts_dir) maker.items.new_item do |item| item.link = item_link item.title = item_title - item.updated = date.to_s - item.pubDate = date.rfc822 + item.updated = date.to_time.to_s + item.pubDate = date.to_time.rfc822 item.description = item_content end end @@ -131,6 +141,7 @@ def generate_rss(posts, rss_file, author_name, site_name, site_url, posts_dir) File.write(rss_file, rss) end + # Process header, posts, pages, etc. header_content = File.read(header_file) |