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 | |
parent | 628fcf941c322dd0ed24a643c58394392484740e (diff) |
feat(new): splash page in progress
Diffstat (limited to 'new')
32 files changed, 413 insertions, 52 deletions
diff --git a/new/Gemfile.lock b/new/Gemfile.lock index dc1f034..d610cfd 100644 --- a/new/Gemfile.lock +++ b/new/Gemfile.lock @@ -1,19 +1,10 @@ GEM remote: https://rubygems.org/ specs: - addressable (2.8.7) - public_suffix (>= 2.0.2, < 7.0) cgi (0.4.1) - childprocess (5.1.0) - logger (~> 1.5) diff-lcs (1.5.1) erb (4.0.4) cgi (>= 0.3.3) - launchy (3.0.1) - addressable (~> 2.8) - childprocess (~> 5.0) - logger (1.6.4) - public_suffix (6.0.1) rexml (3.4.0) rspec (3.13.0) rspec-core (~> 3.13.0) @@ -38,7 +29,6 @@ PLATFORMS DEPENDENCIES erb - launchy rspec rss webrick diff --git a/new/bin/.#server.rb b/new/bin/.#server.rb deleted file mode 120000 index e9c1dc6..0000000 --- a/new/bin/.#server.rb +++ /dev/null @@ -1 +0,0 @@ -mms@voyager.local.45942:1734682989
\ No newline at end of file diff --git a/new/bin/builder.rb b/new/bin/builder.rb new file mode 100644 index 0000000..47195b2 --- /dev/null +++ b/new/bin/builder.rb @@ -0,0 +1,35 @@ +require 'optparse' + +require_relative "../lib/crys" +require_relative "mixins/splash.rb" + +Options = Struct.new(:filepath) +@options = Options.new + +OptionParser.new do |opts| + opts.banner = 'Usage: builder.rb [options]' + + opts.on('-fPATH', '--file=PATH', 'File path') do |n| + @options[:filepath] = n + end +end.parse! + + +module Crys + class BuilderRunner + + def initialize(file_path:, image_dir:, output_dir:, builder_class:) + @file_path = file_path + @output_dir = output_dir + @builder_class = builder_class + @image_dir = image_dir + end + + def run + builder_class.new(file_path: file_path, output_dir: output_dir, image_dir: image_dir).build + end + + private + attr_reader :builder_class, :file_path, :output_dir, :image_dir + end +end diff --git a/new/lib/crys.rb b/new/lib/crys.rb index 333fcfb..68542a0 100644 --- a/new/lib/crys.rb +++ b/new/lib/crys.rb @@ -1,4 +1,8 @@ +require_relative "crys/processors/html_processor.rb" + require_relative "crys/server.rb" +require_relative "crys/builder.rb" +require_relative "crys/image_processor.rb" module Crys end diff --git a/new/lib/crys/code_processor.rb b/new/lib/crys/_code_processor.rb index e69de29..e69de29 100644 --- a/new/lib/crys/code_processor.rb +++ b/new/lib/crys/_code_processor.rb diff --git a/new/lib/crys/default_data.rb b/new/lib/crys/_default_data.rb index 8333669..8333669 100644 --- a/new/lib/crys/default_data.rb +++ b/new/lib/crys/_default_data.rb diff --git a/new/lib/crys/file_watcher.rb b/new/lib/crys/_file_watcher.rb index e69de29..e69de29 100644 --- a/new/lib/crys/file_watcher.rb +++ b/new/lib/crys/_file_watcher.rb diff --git a/new/lib/crys/listing.rb b/new/lib/crys/_listing.rb index e69de29..e69de29 100644 --- a/new/lib/crys/listing.rb +++ b/new/lib/crys/_listing.rb diff --git a/new/lib/crys/new_file.rb b/new/lib/crys/_new_file.rb index e69de29..e69de29 100644 --- a/new/lib/crys/new_file.rb +++ b/new/lib/crys/_new_file.rb diff --git a/new/lib/crys/page_from_erb.rb b/new/lib/crys/_page_from_erb.rb index e69de29..e69de29 100644 --- a/new/lib/crys/page_from_erb.rb +++ b/new/lib/crys/_page_from_erb.rb diff --git a/new/lib/crys/page_from_org.rb b/new/lib/crys/_page_from_org.rb index e69de29..e69de29 100644 --- a/new/lib/crys/page_from_org.rb +++ b/new/lib/crys/_page_from_org.rb diff --git a/new/lib/crys/resource_from_css.rb b/new/lib/crys/_resource_from_css.rb index e69de29..e69de29 100644 --- a/new/lib/crys/resource_from_css.rb +++ b/new/lib/crys/_resource_from_css.rb diff --git a/new/lib/crys/builder.rb b/new/lib/crys/builder.rb new file mode 100644 index 0000000..a3f55b1 --- /dev/null +++ b/new/lib/crys/builder.rb @@ -0,0 +1,50 @@ + +module Crys + class Builder + + + def initialize(file_path:, output_dir:, image_dir:) + @file_path = file_path + @output_dir = output_dir + @processor = processor_class.new(file_path: file_path, image_dir: image_dir) + + end + + def build + process_html + process_assets + end + + private + + attr_reader :file_path, :output_dir, :processor + + def process_assets + processor.assets.each do |asset| + output_path = output_dir + "/" + asset.relative_path + File.open(output_path, 'w') { |file| file.write(asset.processed_asset) } + end + end + + def process_html + html = processor.to_html + filename = processor.filename + output_path = output_dir + "/" + filename + + File.open(output_path, 'w') { |file| file.write(html) } + end + + def processor_class + case file_path + when /html.erb$/ + html_processor + else + raise StandardError.new("No processor for #{file_path}") + end + end + + def html_processor + Crys::HtmlProcessor + end + end +end diff --git a/new/lib/crys/image_processor.rb b/new/lib/crys/image_processor.rb index 1a33d04..b7e2fd6 100644 --- a/new/lib/crys/image_processor.rb +++ b/new/lib/crys/image_processor.rb @@ -1,10 +1,26 @@ module Crys class ImageProcessor - def initialize(path:, width:, height:, format:) + def initialize(path:, filename:, width: :auto) + @path = path + @filename = filename + @file = File.read(path) end - def path + def relative_path + filename + end + + def filename + filename + end + def processed_asset + file.to_s end + + private + + attr_reader :path, :filename, :file + end end diff --git a/new/lib/crys/processors/common_functions.rb b/new/lib/crys/processors/common_functions.rb new file mode 100644 index 0000000..f33c768 --- /dev/null +++ b/new/lib/crys/processors/common_functions.rb @@ -0,0 +1,31 @@ +require 'rss' + +module Crys + module CommonFunctions + def project_root + "#{File.dirname(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))))}" + end + + def process_image(file:, width: :auto) + full_path = image_dir + "/" + file + + image = ::Crys::ImageProcessor.new(path: full_path, filename: file, width: width) + assets << image + + image + end + + def fetch_rss(url: nil, name: nil) + if name + path = case name + when :main + "/public/index.xml" + end + + rss = File.read(project_root + path) + end + + RSS::Parser.parse(rss) + end + end +end diff --git a/new/lib/crys/processors/common_parts.rb b/new/lib/crys/processors/common_parts.rb new file mode 100644 index 0000000..1dbf6d8 --- /dev/null +++ b/new/lib/crys/processors/common_parts.rb @@ -0,0 +1,20 @@ +module Crys + module CommonParts + def webbutton(file:, url:, alt:) + full_path = image_dir + "/buttons/" + file + + image = ::Crys::ImageProcessor.new(path: full_path, filename: file, width: 88) + assets << image + + code = ERB.new <<-EOF +<a href="<%=url%>"> +<img src="<%=image.relative_path%>" width="88" height="31" class="webbutton" alt="<%=alt%>"> +</a> +EOF + + code.result(binding) + + end + + end +end diff --git a/new/lib/crys/processors/html_processor.rb b/new/lib/crys/processors/html_processor.rb new file mode 100644 index 0000000..d5ea73d --- /dev/null +++ b/new/lib/crys/processors/html_processor.rb @@ -0,0 +1,38 @@ +require 'erb' +require_relative "common_functions" +require_relative "common_parts" + +module Crys + class HtmlProcessor + + include CommonFunctions + include CommonParts + + def initialize(file_path:, image_dir:) + @file_path = file_path + @image_dir = image_dir + @assets = [] + end + + def to_html + html_file = ERB.new(File.read(file_path)) + html_file.result(local_binding) + end + + + def filename + file_path.scan(/.*\/(.*)\.erb/).flatten.first + end + + attr_reader :assets + + private + + attr_reader :file_path, :image_dir + attr_writer :assets + + def local_binding + local_binding ||= binding.clone + end + end +end diff --git a/new/lib/crys/renderer.rb b/new/lib/crys/renderer.rb deleted file mode 100644 index c490330..0000000 --- a/new/lib/crys/renderer.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'erb' -require 'pry' - -module Crys - module Splash - class Theme - PARENT_DIR = File.expand_path(".", Dir.pwd) - - def render - template = ERB.new(File.read(PARENT_DIR + "/theme/" + self.class::PAGE)) - template.result(local_binding) - end - - def body - self.class::BODY.result(local_binding) - end - - private - - attr_accessor :template, :data - - def local_binding - local_binding = binding.clone - self.class::DATA.each do |k, v| - local_binding.local_variable_set(k,v) - end - local_binding - - end - end - end -end diff --git a/new/splash/assets/images/background.png b/new/splash/assets/images/background.png Binary files differnew file mode 100644 index 0000000..11f85e6 --- /dev/null +++ b/new/splash/assets/images/background.png diff --git a/new/splash/assets/images/buttons/org.dillo.gif b/new/splash/assets/images/buttons/org.dillo.gif Binary files differnew file mode 100644 index 0000000..850d4df --- /dev/null +++ b/new/splash/assets/images/buttons/org.dillo.gif diff --git a/new/splash/assets/images/buttons/org.freebsd.gif b/new/splash/assets/images/buttons/org.freebsd.gif Binary files differnew file mode 100644 index 0000000..cd41141 --- /dev/null +++ b/new/splash/assets/images/buttons/org.freebsd.gif diff --git a/new/splash/assets/images/new.gif b/new/splash/assets/images/new.gif Binary files differnew file mode 100644 index 0000000..b06fb07 --- /dev/null +++ b/new/splash/assets/images/new.gif diff --git a/new/splash/bin/build.rb b/new/splash/bin/build.rb index 404431f..1439dd6 100755 --- a/new/splash/bin/build.rb +++ b/new/splash/bin/build.rb @@ -6,6 +6,14 @@ require_relative '../../bin/builder' builder_class = Crys::Splash::Builder output_dir = "#{File.dirname(File.dirname(__FILE__))}/output" -file_path = "#{File.dirname(File.dirname(__FILE__))}/pages/#{@options[:filepath]}" +#file_path = "#{File.dirname(File.dirname(__FILE__))}/pages/#{@options[:filepath]}" +image_dir = "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/assets/images" -Crys::BuilderRunner.new(file_path: file_path, output_dir: output_dir, builder_class: builder_class).run +file_path=@options[:filepath] + +Crys::BuilderRunner.new( + file_path: file_path, + output_dir: output_dir, + builder_class: builder_class, + image_dir: image_dir +).run 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 diff --git a/new/splash/output/background.png b/new/splash/output/background.png Binary files differnew file mode 100644 index 0000000..11f85e6 --- /dev/null +++ b/new/splash/output/background.png diff --git a/new/splash/output/new.gif b/new/splash/output/new.gif Binary files differnew file mode 100644 index 0000000..b06fb07 --- /dev/null +++ b/new/splash/output/new.gif diff --git a/new/splash/output/org.dillo.gif b/new/splash/output/org.dillo.gif Binary files differnew file mode 100644 index 0000000..850d4df --- /dev/null +++ b/new/splash/output/org.dillo.gif diff --git a/new/splash/output/org.freebsd.gif b/new/splash/output/org.freebsd.gif Binary files differnew file mode 100644 index 0000000..cd41141 --- /dev/null +++ b/new/splash/output/org.freebsd.gif diff --git a/new/splash/pages/.dir-locals.el b/new/splash/pages/.dir-locals.el index 4e2be03..22b2f46 100644 --- a/new/splash/pages/.dir-locals.el +++ b/new/splash/pages/.dir-locals.el @@ -1 +1,6 @@ -((nil . ((add-hook 'after-save-hook ('message :a)))) + +((nil + . ((eval . + (add-hook 'after-save-hook (lambda () (message (shell-command-to-string (format "../bin/build.rb -f%s" (buffer-file-name)))))) + )))) + diff --git a/new/splash/pages/background.png b/new/splash/pages/background.png new file mode 100644 index 0000000..22d26b7 --- /dev/null +++ b/new/splash/pages/background.png @@ -0,0 +1 @@ +#<File:0x0000293dcce70da0>
\ No newline at end of file diff --git a/new/splash/pages/index.html.erb b/new/splash/pages/index.html.erb index d033c90..e5ee6f6 100644 --- a/new/splash/pages/index.html.erb +++ b/new/splash/pages/index.html.erb @@ -1,9 +1,146 @@ -<html> +<!DOCTYPE html> +<html lang="en"> <head> - <title>It works!</title> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <meta charset="utf-8"> + <title>Crys SITE</title> + <link rel="canonical" href="https://crys.site"> + <meta name="robots" content="index, follow"> + <meta property="og:title" content="Crys Site"> + <meta property="og:type" content="website"> + <meta property="og:url" content="https://crys.site"> + <meta property="og:description" content="Michal's personal website"> + + <meta name="fediverse:creator" content="@mms@bsd.cafe"> + <link rel="me" href="https://mastodon.bsd.cafe/@mms" title="@mms on bsd.cafe"> + + <style> + body { + text-align: center; + background-color: #c2c2c2; + background-image: url("<%= process_image(file: "background.png").relative_path %>"); + color: #000; + } + + a { + color: #000; + } + ol { + padding: 0; + } + + ol li{ + list-style-type: none; + } + + img.webutton { + border: 0; + text-decoration: none; + color: #c2c2c2; + margin: 10px; + } + + </style> + </head> <body> - <h1>Test</h1> - Last update: <%= Time.now %> + + <h1>Crys SITE</h1> + + <p> + Hi! + I'm Michal and this is my personal webpage. + </p> + + <p> + The World Wide Web used to be fun, scrappy, and ours; let's bring it back. + </p> + + <p> + <b>NOTE: I am not a real <%= not_real %>, and I can be wrong sometimes</b>. + + </p> + + + <hr> + <p> + Updated <%= Time.now.strftime("%B %d, %Y") %> + </p> + + <hr> + <h2>Contents</h2> + + <h3>Main sections</h3> + + + <nav> + <ol> + <li><a href="/blog">My personal blog</a> + <%= update_badge("blog")%> + <li><a href="/bsd">Guides on using FreeBSD on a PC</a> + <%= update_badge("bsd")%> + <li><a href="/emacs">Guides on using Emacs for not obvious tasks</a> + <%= update_badge("emacs")%> + <li><a href="/unix-history">A short Unix History</a> + <%= update_badge("unix-history")%> + <li><a href="/reviews">Reviews of narrative works</a> + <%= update_badge("reviews")%> + <li><a href="/star-trek">Star Trek fansite</a> + <%= update_badge("star-trek")%> + </ol> + + + <h3>Projects</h3> + + <ol> + <li><a href="/projects/chotto">Chotto</a> - a initial tagging system for Notmuch + <%= update_badge("chotto")%> + </ol> + + + <h3>Mirrors</h3> + <ol> + <li><a href="/mirror/userfriendly">User Friendly comic mirror</a> + </ol> + + <h3>Even more</h3> + + + <ol> + <li><a href="/more/bookmarks/">Bookmarks</a> to cool things on the web + <%= more_update_badge(name: :bookmarks)%> + <li><a href="/more/links/">Links</a> to other sites + <%= more_update_badge(name: :links)%> + <li><a href="/more/irc/">IRC Channel</a> of this site + <li><a href="/more/contact/">Contact</a> + <li><a href="/more/now/">Now</a> + <li><a href="/more/uses/">Uses</a> + </ol> + +</nav> + <hr> + + + <h2>Recent updates</h2> + + <nav> + <ol> + <% fetch_rss(name: :main).items.first(10).each do |item| %> + <li><a href="<%=item.link%>"><%= item.title %></a> (<%=item.date.strftime("%B %d, %Y")%>) + <% end %> + </ol> + </nav> + + + <hr> + <p> + This is self-hosted site. + You are connected live to my living room. + </p> + + <div> + <%= webbutton(file: "org.freebsd.gif", url: "https://www.freebsd.org/", alt: "Powered by FreeBSD") %> + <%= webbutton(file: "org.dillo.gif", url: "https://www.dillo.org/", alt: "Optimized for Dillo") %> + </div> </body> </html> |