diff options
author | Bradley Taunt <bt@btxx.org> | 2024-07-20 12:32:52 -0400 |
---|---|---|
committer | Bradley Taunt <bt@btxx.org> | 2024-07-20 12:32:52 -0400 |
commit | 1cdc8ad6d15f4b01b6ab79a57614dc304aba1d3c (patch) | |
tree | 80146ba09b1c91e5d4974117f843f9e1a835a1c3 | |
parent | b810d9a0b47dd49a90cc8ec7bf1b05f59ff945b3 (diff) |
Crude testing with blogrb with RSS
-rw-r--r-- | .build.yml | 2 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | blog.rb | 37 |
3 files changed, 37 insertions, 4 deletions
@@ -10,7 +10,7 @@ sources: - https://git.sr.ht/~bt/btxx.org tasks: - install-gems: | - sudo gem install kramdown fileutils + sudo gem install kramdown fileutils rss - build: | cd btxx.org make build @@ -1,8 +1,6 @@ build: rm -rf build && mkdir build ruby blog.rb - rsync -r public/ build/public - rsync style.css build/style.css clean: rm -rf build/* @@ -1,20 +1,29 @@ require 'kramdown' require 'fileutils' require 'date' +require 'rss' # Define all the things +site_url = 'https://bt.srht.site' +site_name = 'btxx.org' +author_name = 'Bradley Taunt' + posts_dir = 'posts' pages_dir = 'pages' wiki_dir = 'pages/wiki' recipes_dir = 'pages/recipes' +public_dir = 'public' + output_dir = 'build' posts_output_dir = "#{output_dir}/posts" pages_output_dir = "#{output_dir}/" wiki_output_dir = "#{output_dir}/wiki/" recipes_output_dir = "#{output_dir}/recipes/" + header_file = 'header.html' footer_file = 'footer.html' root_index_file = 'index.md' +rss_file = "#{output_dir}/rss.xml" # Make sure output directories exist FileUtils.mkdir_p(posts_output_dir) @@ -87,7 +96,7 @@ def process_markdown_files(input_directory, output_directory, content_array, hea end # Add item information to the array - content_array << { title: title, date: date, link: "#{output_directory.split('/').last}/#{file_name}/" } + content_array << { title: title, date: date, link: "#{output_directory.split('/').last}/#{file_name}/", content: html_content } end end @@ -127,9 +136,35 @@ end index_content << "</ul>\n" index_content << footer_content +# Copy the public directory to the build directory +FileUtils.cp_r("#{public_dir}/.", output_dir) + # Write the index file File.open("#{output_dir}/index.html", 'w') do |file| file.write(index_content) end +# Generate RSS feed +rss = RSS::Maker.make("atom") do |maker| + maker.channel.author = "#{author_name}" + maker.channel.updated = Time.now.to_s + maker.channel.about = "#{site_name}" + maker.channel.title = "#{site_name} RSS Feed" + + posts.each do |post| + maker.items.new_item do |item| + item.link = "#{site_url}/#{post[:link]}" + item.title = post[:title] + item.updated = post[:date].to_s + item.content.type = 'html' + item.content.content = post[:content] + end + end +end + +# Write RSS file +File.open(rss_file, 'w') do |file| + file.write(rss) +end + puts "Blog built successfully in '#{output_dir}' folder. Have a great day!" |