diff options
author | Bradley Taunt <bt@btxx.org> | 2024-07-21 13:55:39 -0400 |
---|---|---|
committer | Bradley Taunt <bt@btxx.org> | 2024-07-21 13:55:39 -0400 |
commit | b2a50d585d23699e951a2183ac119826a0f47ac8 (patch) | |
tree | 988ea24609742296769ac87b75a8bc5f274631d8 | |
parent | 34d1e1144d1f47c37e2b2d9c251f6c86029a5986 (diff) |
Update wruby to dynamically handle pages subdirectories, regardless of depth
-rw-r--r-- | wruby.rb | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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!" + + |