summaryrefslogtreecommitdiff
path: root/new/splash/lib
diff options
context:
space:
mode:
Diffstat (limited to 'new/splash/lib')
-rw-r--r--new/splash/lib/splash/builder.rb6
-rw-r--r--new/splash/lib/splash/processors/splash_processor.rb53
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