Site Summary at Build
I added a ruby script to print a blog summary at build. I will probably not read it every time, but it is good to have a simple way of checking the count of posts. Code below:
# _plugins/site_summary.rb
module Jekyll
class SiteSummaryHook
Jekyll::Hooks.register :site, :post_render do |site|
puts "\n--------------------"
puts "--- Site Summary ---"
puts "--------------------\n\n"
# Total number of posts
total_posts = site.posts.docs.size
puts "Total number of posts: #{total_posts}\n\n"
# List of categories and number of posts in each
categories = Hash.new(0)
site.posts.docs.each do |post|
(post.data['categories'] || []).each { |category| categories[category] += 1 }
end
puts "List of categories with post counts:"
categories.sort_by { |category, count| -count }.each do |category, count|
puts "\t#{count}\t#{category}"
end
# Example: List of tags
tags = Hash.new(0)
site.posts.docs.each do |post|
(post.data['tags'] || []).each { |tag| tags[tag] += 1 }
end
puts "\nList of tags with post counts:"
tags.sort_by { |tag, count| -count }.each do |tag, count|
puts "\t#{count}\t#{tag}"
end
puts "\n--------------------"
puts "-- End of Summary --"
puts "--------------------\n\n"
end
end
end
As an example, this is how the output looks like:
--------------------
--- Site Summary ---
--------------------
Total number of posts: 43
List of categories with post counts:
25 journal-site-updates
4 tutorial-git
3 journal-revit-api
3 journal-cs
3 journal-other
2 articles
2 tutorial-one-page
1 tutorial-vba
List of tags with post counts:
20 jekyll
10 web-design
6 c#
5 github
4 liquid
4 html
4 git
4 python
4 ruby
3 google-analytics
3 javascript
3 jekyll-liquid
3 revit-api
2 jekyll-minima
2 css
2 portfolio
2 netlify
2 linux
1 scripting
1 docker
1 paths
1 autocad
1 markdown
1 obsidian
1 render
1 bash
1 linux-mint
1 ubuntu
1 cron
1 vba
1 github-actions
--------------------
-- End of Summary --
--------------------
Once pushed changes to main
, the output shown above can be seen in Netlify under Deploy Log > Building. If I want to see the above summary in development, since I am using docker, I need to use the option --interactive
or -i
- see command below.
docker start my-container-name -i