aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Taunt <bt@btxx.org>2024-07-21 13:55:39 -0400
committerBradley Taunt <bt@btxx.org>2024-07-21 13:55:39 -0400
commitb2a50d585d23699e951a2183ac119826a0f47ac8 (patch)
tree988ea24609742296769ac87b75a8bc5f274631d8
parent34d1e1144d1f47c37e2b2d9c251f6c86029a5986 (diff)
Update wruby to dynamically handle pages subdirectories, regardless of depth
-rw-r--r--wruby.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/wruby.rb b/wruby.rb
index 9ff6cf4..707b64c 100644
--- a/wruby.rb
+++ b/wruby.rb
@@ -2,6 +2,7 @@ require 'kramdown'
require 'fileutils'
require 'date'
require 'rss'
+require 'find'
# Configuration all the things!
site_url = 'https://wruby.btxx.org'
@@ -42,15 +43,17 @@ end
def process_markdown_files(input_directory, output_directory, header_content, footer_content)
items = []
- Dir.glob("#{input_directory}/**/*.md").each do |md_file|
- md_content = File.read(md_file)
+ Find.find(input_directory) do |path|
+ next unless path =~ /\.md\z/
+
+ md_content = File.read(path)
lines = md_content.lines
title = extract_title_from_md(lines)
date = Date.parse(lines[2]&.strip || '') rescue Date.today
html_content = Kramdown::Document.new(md_content).to_html
- relative_path = md_file.sub(input_directory + '/', '').sub('.md', '')
+ relative_path = path.sub(input_directory + '/', '').sub('.md', '')
item_dir = File.join(output_directory, relative_path)
output_file = "#{item_dir}/index.html"
FileUtils.mkdir_p(item_dir)
@@ -112,3 +115,5 @@ FileUtils.cp_r(public_dir, output_dir)
generate_rss(posts, rss_file, author_name, site_name, site_url)
puts "Blog built successfully in '#{output_dir}' folder. Have a great day!"
+
+