samhuri.net/lib/pressa/views/feed_post_view.rb
Sami Samhuri 007b1058b6
Migrate from Swift to Ruby (#33)
Replace the Swift site generator with a Ruby and Phlex implementation.
Loads site and projects from TOML, derive site metadata from posts.

Migrate from make to bake and add standardrb and code coverage tasks.

Update CI and docs to match the new workflow, and remove unused
assets/dependencies plus obsolete tooling.
2026-02-07 21:19:03 -08:00

33 lines
750 B
Ruby

require "phlex"
module Pressa
module Views
class FeedPostView < Phlex::HTML
def initialize(post:, site:)
@post = post
@site = site
end
def view_template
div do
p(class: "time") { @post.formatted_date }
raw(safe(normalized_body))
p do
a(class: "permalink", href: @site.url_for(@post.path)) { "" }
end
end
end
private
def normalized_body
@post.body.gsub(/(href|src)=(['"])(\/(?!\/)[^'"]*)\2/) do
attr = Regexp.last_match(1)
quote = Regexp.last_match(2)
path = Regexp.last_match(3)
%(#{attr}=#{quote}#{@site.url_for(path)}#{quote})
end
end
end
end
end