samhuri.net/lib/pressa/posts/plugin.rb
Sami Samhuri e43bb0a71b Add tag tooling: bake tags report and unlinked /tags/ pages
Adds Posts::TagIndex (counts, per-tag posts, per-tag/year breakdown)
and Posts::TagReport, wired into a new `bake tags` task that prints a
frequency table plus a tag-by-year sparkline straight to the terminal.

Also generates /tags/ and /tags/<tag>/ HTML pages via the existing
Posts plugin, listing tags with post counts and per-tag post listings.
Not linked from nav yet -- reachable by URL only until tags are
curated enough to surface properly.

Extracted PostListItemView out of YearPostsView so the post-link
rendering (incl. link posts) is shared with the new tag pages instead
of duplicated.
2026-06-21 20:43:30 -07:00

63 lines
1.9 KiB
Ruby

require "pressa/plugin"
require "pressa/posts/repo"
require "pressa/posts/writer"
require "pressa/posts/gemini_writer"
require "pressa/posts/json_feed"
require "pressa/posts/rss_feed"
require "pressa/posts/tag_index"
module Pressa
module Posts
class BasePlugin < Pressa::Plugin
attr_reader :posts_by_year
def setup(site:, source_path:)
posts_dir = File.join(source_path, "posts")
return unless Dir.exist?(posts_dir)
repo = PostRepo.new
@posts_by_year = repo.read_posts(posts_dir)
end
end
class HTMLPlugin < BasePlugin
def render(site:, target_path:)
return unless @posts_by_year
writer = PostWriter.new(site:, posts_by_year: @posts_by_year)
writer.write_posts(target_path:)
writer.write_recent_posts(target_path:, limit: 10)
writer.write_posts_archive(target_path:)
writer.write_year_indexes(target_path:)
writer.write_month_rollups(target_path:)
writer.write_tags_index(target_path:)
writer.write_tag_pages(target_path:)
json_feed = JSONFeedWriter.new(site:, posts_by_year: @posts_by_year)
json_feed.write_feed(target_path:, limit: 30)
rss_feed = RSSFeedWriter.new(site:, posts_by_year: @posts_by_year)
rss_feed.write_feed(target_path:, limit: 30)
end
end
class GeminiPlugin < BasePlugin
def render(site:, target_path:)
return unless @posts_by_year
writer = GeminiWriter.new(site:, posts_by_year: @posts_by_year)
writer.write_posts(target_path:)
writer.write_recent_posts(target_path:, limit: gemini_recent_posts_limit(site))
writer.write_posts_index(target_path:)
end
private
def gemini_recent_posts_limit(site)
site.gemini_output_options&.recent_posts_limit || GeminiWriter::RECENT_POSTS_LIMIT
end
end
Plugin = HTMLPlugin
end
end