aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Taunt <bt@btxx.org>2024-07-20 12:32:52 -0400
committerBradley Taunt <bt@btxx.org>2024-07-20 12:32:52 -0400
commit1cdc8ad6d15f4b01b6ab79a57614dc304aba1d3c (patch)
tree80146ba09b1c91e5d4974117f843f9e1a835a1c3
parentb810d9a0b47dd49a90cc8ec7bf1b05f59ff945b3 (diff)
Crude testing with blogrb with RSS
-rw-r--r--.build.yml2
-rw-r--r--Makefile2
-rw-r--r--blog.rb37
3 files changed, 37 insertions, 4 deletions
diff --git a/.build.yml b/.build.yml
index e6ed51c..0e29619 100644
--- a/.build.yml
+++ b/.build.yml
@@ -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
diff --git a/Makefile b/Makefile
index 1e65980..769d796 100644
--- a/Makefile
+++ b/Makefile
@@ -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/*
diff --git a/blog.rb b/blog.rb
index 8312cbd..17b226c 100644
--- a/blog.rb
+++ b/blog.rb
@@ -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!"