mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +00:00
* Publish on gemini in addition to the web * Publish gemini feeds, add link from web, tweak things
138 lines
3.5 KiB
Ruby
138 lines
3.5 KiB
Ruby
require "pressa/plugin"
|
|
require "pressa/utils/file_writer"
|
|
require "pressa/views/layout"
|
|
require "pressa/views/projects_view"
|
|
require "pressa/views/project_view"
|
|
require "pressa/projects/models"
|
|
|
|
module Pressa
|
|
module Projects
|
|
class HTMLPlugin < Pressa::Plugin
|
|
attr_reader :scripts, :styles
|
|
|
|
def initialize(projects: [], scripts: [], styles: [])
|
|
@projects = projects
|
|
@scripts = scripts
|
|
@styles = styles
|
|
end
|
|
|
|
def setup(site:, source_path:)
|
|
end
|
|
|
|
def render(site:, target_path:)
|
|
write_projects_index(site:, target_path:)
|
|
|
|
@projects.each do |project|
|
|
write_project_page(project:, site:, target_path:)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def write_projects_index(site:, target_path:)
|
|
content_view = Views::ProjectsView.new(projects: @projects, site:)
|
|
|
|
html = render_layout(
|
|
site:,
|
|
page_subtitle: "Projects",
|
|
canonical_url: site.url_for("/projects/"),
|
|
content: content_view
|
|
)
|
|
|
|
file_path = File.join(target_path, "projects", "index.html")
|
|
Utils::FileWriter.write(path: file_path, content: html)
|
|
end
|
|
|
|
def write_project_page(project:, site:, target_path:)
|
|
content_view = Views::ProjectView.new(project:, site:)
|
|
|
|
html = render_layout(
|
|
site:,
|
|
page_subtitle: project.title,
|
|
canonical_url: site.url_for(project.path),
|
|
content: content_view,
|
|
page_scripts: @scripts,
|
|
page_styles: @styles,
|
|
page_description: project.description
|
|
)
|
|
|
|
file_path = File.join(target_path, "projects", project.name, "index.html")
|
|
Utils::FileWriter.write(path: file_path, content: html)
|
|
end
|
|
|
|
def render_layout(
|
|
site:,
|
|
page_subtitle:,
|
|
canonical_url:,
|
|
content:,
|
|
page_scripts: [],
|
|
page_styles: [],
|
|
page_description: nil
|
|
)
|
|
layout = Views::Layout.new(
|
|
site:,
|
|
page_subtitle:,
|
|
canonical_url:,
|
|
page_scripts:,
|
|
page_styles:,
|
|
page_description:,
|
|
content:
|
|
)
|
|
|
|
layout.call
|
|
end
|
|
end
|
|
|
|
class GeminiPlugin < Pressa::Plugin
|
|
def initialize(projects: [])
|
|
@projects = projects
|
|
end
|
|
|
|
def setup(site:, source_path:)
|
|
end
|
|
|
|
def render(site:, target_path:)
|
|
write_projects_index(site:, target_path:)
|
|
|
|
@projects.each do |project|
|
|
write_project_page(project:, site:, target_path:)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def write_projects_index(site:, target_path:)
|
|
rows = ["# Projects", ""]
|
|
@projects.each do |project|
|
|
rows << "## #{project.title}"
|
|
rows << project.description
|
|
rows << "=> #{project.url}"
|
|
rows << ""
|
|
end
|
|
rows << "=> / Home"
|
|
rows << "=> #{site.url_for("/projects/")} Read on the web"
|
|
rows << ""
|
|
|
|
file_path = File.join(target_path, "projects", "index.gmi")
|
|
Utils::FileWriter.write(path: file_path, content: rows.join("\n"))
|
|
end
|
|
|
|
def write_project_page(project:, site:, target_path:)
|
|
rows = [
|
|
"# #{project.title}",
|
|
"",
|
|
project.description,
|
|
"",
|
|
"=> #{project.url}",
|
|
"=> /projects/ Back to projects",
|
|
""
|
|
]
|
|
|
|
file_path = File.join(target_path, "projects", project.name, "index.gmi")
|
|
Utils::FileWriter.write(path: file_path, content: rows.join("\n"))
|
|
end
|
|
end
|
|
|
|
Plugin = HTMLPlugin
|
|
end
|
|
end
|