diff options
-rw-r--r-- | _config.yml | 21 | ||||
-rw-r--r-- | footer.html | 1 | ||||
-rw-r--r-- | header.html | 3 | ||||
-rw-r--r-- | pages/posts.md | 3 | ||||
-rw-r--r-- | wruby.rb | 59 |
5 files changed, 66 insertions, 21 deletions
diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..992eed7 --- /dev/null +++ b/_config.yml @@ -0,0 +1,21 @@ +site_url: 'https://bt.srht.site' +site_name: 'bt' +author_name: 'Bradley Taunt' + +directories: + posts: 'posts' + pages: 'pages' + public: 'public' + output: 'build' + posts_output: 'build/posts' + pages_output: 'build/' + +files: + header: 'header.html' + footer: 'footer.html' + root_index: 'index.md' + posts_index: 'pages/posts.md' + rss: 'build/index.rss' + +misc: + post_count: 5 diff --git a/footer.html b/footer.html index 6d930c0..3f01220 100644 --- a/footer.html +++ b/footer.html @@ -4,6 +4,7 @@ <h2>Menu Navigation</h2> <ul id="menu"> <li><a href="/">Home</a></li> + <li><a href="/posts">Posts</a></li> <li><a href="/projects">Projects</a></li> <li><a href="/uses">Uses</a></li> <li><a href="/wiki">Wiki</a></li> diff --git a/header.html b/header.html index e4ac235..89ed43e 100644 --- a/header.html +++ b/header.html @@ -6,8 +6,7 @@ <meta name="color-scheme" content="dark light"> <link rel="icon" href="data:,"> <title>{{TITLE}}</title> - <link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" /> - <link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" /> + <link href="/index.rss" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" /> <style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}blockquote{border-left:4px solid;padding-left:5px;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.posts,#menu{list-style:none;padding:0;}.posts li{margin-bottom:8px;}.posts li span{display:block;font-size:90%;}#menu li{display:inline-block;margin-right:8px;}.footnotes{font-size:90%;}</style> diff --git a/pages/posts.md b/pages/posts.md new file mode 100644 index 0000000..14ecfca --- /dev/null +++ b/pages/posts.md @@ -0,0 +1,3 @@ +# Posts + +This page contains a full list of all my blog posts.
\ No newline at end of file @@ -4,24 +4,29 @@ require 'date' require 'time' require 'rss' require 'find' +require 'yaml' -# Configuration all the things! -site_url = 'https://bt.srht.site' -site_name = 'bt' -author_name = 'Bradley Taunt' +# Load configuration +config = YAML.load_file('_config.yml') -posts_dir = 'posts' -pages_dir = 'pages' -public_dir = 'public' +site_url = config['site_url'] +site_name = config['site_name'] +author_name = config['author_name'] -output_dir = 'build' -posts_output_dir = "#{output_dir}/posts" -pages_output_dir = "#{output_dir}/" +posts_dir = config['directories']['posts'] +pages_dir = config['directories']['pages'] +public_dir = config['directories']['public'] +output_dir = config['directories']['output'] +posts_output_dir = config['directories']['posts_output'] +pages_output_dir = config['directories']['pages_output'] -header_file = 'header.html' -footer_file = 'footer.html' -root_index_file = 'index.md' -rss_file = "#{output_dir}/index.rss" +header_file = config['files']['header'] +footer_file = config['files']['footer'] +root_index_file = config['files']['root_index'] +posts_index_file = config['files']['posts_index'] +rss_file = config['files']['rss'] + +post_count = config['misc']['post_count'] # Make sure output directories exist [posts_output_dir, pages_output_dir].each { |dir| FileUtils.mkdir_p(dir) } @@ -69,7 +74,7 @@ def process_markdown_files(input_directory, output_directory, header_content, fo end # Create the root index file -def generate_index(posts, header_content, footer_content, root_index_file, output_dir, posts_dir) +def generate_index(posts, header_content, footer_content, root_index_file, post_count, output_dir, posts_dir) root_index_content = File.read(root_index_file) root_title = extract_title_from_md(root_index_content.lines) root_html = Kramdown::Document.new(root_index_content).to_html @@ -77,13 +82,28 @@ def generate_index(posts, header_content, footer_content, root_index_file, outpu header = replace_title_placeholder(header_content, root_title) index_content = header + root_html + "<ul class=\"posts\">\n" - posts.each { |post| index_content << "<li><span>#{post[:date]}</span><a href='/#{posts_dir}/#{post[:link]}'>#{post[:title]}</a></li>\n" } - index_content << "</ul>\n" + footer_content + posts.first(post_count).each { |post| index_content << "<li><span>#{post[:date]}</span><a href='/#{posts_dir}/#{post[:link]}'>#{post[:title]}</a></li>\n" } + index_content << "</ul>\n<p><a href='/#{posts_dir}'>View all posts →</a></p>\n" + footer_content File.write("#{output_dir}/index.html", index_content) end -# Generate the RSS feed +# Create the full posts list page +def generate_full_posts_list(posts, header_content, footer_content, posts_index_file, output_dir, posts_dir) + posts_index_content = File.read(posts_index_file) + posts_title = extract_title_from_md(posts_index_content.lines) + posts_html = Kramdown::Document.new(posts_index_content).to_html + + header = replace_title_placeholder(header_content, posts_title) + + list_content = header + posts_html + "<ul class=\"posts\">\n" + posts.each { |post| list_content << "<li><span>#{post[:date]}</span><a href='/#{posts_dir}/#{post[:link]}'>#{post[:title]}</a></li>\n" } + list_content << "</ul>\n" + footer_content + + File.write("#{output_dir}/posts/index.html", list_content) +end + +# Generate the RSS 2.0 feed def generate_rss(posts, rss_file, author_name, site_name, site_url, posts_dir) rss = RSS::Maker.make("2.0") do |maker| maker.channel.author = author_name @@ -117,7 +137,8 @@ header_content = File.read(header_file) posts = process_markdown_files(posts_dir, posts_output_dir, header_content, footer_content).sort_by { |post| -post[:date].to_time.to_i } pages = process_markdown_files(pages_dir, pages_output_dir, header_content, footer_content) -generate_index(posts, header_content, footer_content, root_index_file, output_dir, posts_dir) +generate_index(posts, header_content, footer_content, root_index_file, post_count, output_dir, posts_dir) +generate_full_posts_list(posts, header_content, footer_content, posts_index_file, output_dir, posts_dir) FileUtils.cp_r(public_dir, output_dir) generate_rss(posts, rss_file, author_name, site_name, site_url, posts_dir) |