diff options
author | mms <git@sapka.me> | 2025-01-05 22:34:55 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2025-01-05 22:34:55 +0100 |
commit | bfd8209ad0d80b5027bea8a1a095dadc8bffdc61 (patch) | |
tree | 1d4ec6d63dd3b4a1f788ec340a0fba3cd48b3dea /new/splash/lib | |
parent | 628fcf941c322dd0ed24a643c58394392484740e (diff) |
Diffstat (limited to 'new/splash/lib')
-rw-r--r-- | new/splash/lib/splash/builder.rb | 6 | ||||
-rw-r--r-- | new/splash/lib/splash/processors/splash_processor.rb | 53 |
2 files changed, 59 insertions, 0 deletions
diff --git a/new/splash/lib/splash/builder.rb b/new/splash/lib/splash/builder.rb index 5a737e9..7b0f13f 100644 --- a/new/splash/lib/splash/builder.rb +++ b/new/splash/lib/splash/builder.rb @@ -1,8 +1,14 @@ # frozen_string_literal: true +require_relative "processors/splash_processor" + module Crys module Splash class Builder < Crys::Builder + + def html_processor + Crys::Splash::SplashProcessor + end end end end diff --git a/new/splash/lib/splash/processors/splash_processor.rb b/new/splash/lib/splash/processors/splash_processor.rb new file mode 100644 index 0000000..463dd65 --- /dev/null +++ b/new/splash/lib/splash/processors/splash_processor.rb @@ -0,0 +1,53 @@ +require "yaml" + +module Crys + module Splash + class SplashProcessor < Crys::HtmlProcessor + def not_real + [ + "doctor", + "starfleet officer", + "magician", + "hacker", + "emperor of an evil galaxy", + "replicant", + "computer", + "evil genius" + ].sample + end + + def update_badge(url_part) + @main_rss = fetch_rss(name: :main) + if @main_rss.items.last(20).any? { |it| it.link.include? url_part } + new_badge + end + end + + def more_update_badge(name:) + path = case name + when :bookmarks + "/assets/more/bookmarks.yml" + when :links + "/assets/more/links.yml" + end + + yaml = YAML.load_file(project_root + path) + _, vals = yaml.first + last_added = Time.parse(vals.last.fetch("date")) + + if (Time.now - last_added) / (24 * 60* 60) < 30 + new_badge + end + end + + + def new_badge + image = process_image(file: "new.gif") + code = ERB.new <<-EOF +<img src="<%=image.relative_path%>" width="32" height="22" class="new-badge" alt="NEW"> +EOF + code.result(binding) + end + end + end +end |