From d2a6023d2bf19b08ca61baf809a8b3b526e41169 Mon Sep 17 00:00:00 2001 From: Bradley Taunt Date: Tue, 23 Jul 2024 09:36:35 -0400 Subject: Pull out configuration into separate file,update homepage post count, default post index page --- README.md | 8 +++++++- _config.yml | 21 +++++++++++++++++++++ footer.html | 1 + header.html | 3 +-- pages/posts.md | 3 +++ wruby.rb | 57 +++++++++++++++++++++++++++++++++++++++------------------ 6 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 _config.yml create mode 100644 pages/posts.md diff --git a/README.md b/README.md index ab4c3fe..1552e33 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ gem install kramdown rss ## Getting Started -Make your changes in the top of the main `wruby.rb` file (site URL, your name, +Make your changes in the main configuration file `_config.yml` file (site URL, your name, etc.). Remove the `.build.yml` unless you plan to host with sourcehut pages, otherwise edit this file with your own details. @@ -28,6 +28,12 @@ otherwise edit this file with your own details. * Pages go under the `pages` directory as markdown files * Media (images, videos etc) go in the root `public` directory +## Defaults + +* The homepage only displays the first `5` posts. You can configure this in `_config.yml` under `post_count`. +* The full blog post index will be generated at `yoursite.com/posts` + * This means you need to have a `posts.md` file in your `pages` directory (or change `posts_index` the core `_config.yml`) + ## Running 1. Run `make build` in the root directory diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..019c3ef --- /dev/null +++ b/_config.yml @@ -0,0 +1,21 @@ +site_url: 'https://wruby.btxx.org' +site_name: 'wruby' +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 f2d568a..cc18228 100644 --- a/footer.html +++ b/footer.html @@ -4,6 +4,7 @@

Menu Navigation

\n

View all posts →

\n" + footer_content File.write("#{output_dir}/index.html", index_content) end +# 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 + "\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| @@ -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) -- cgit v1.2.3-54-g00ecf