Add editable pages

This commit is contained in:
2023-11-18 11:01:14 +11:00
parent 484259fab1
commit 53434423fd
25 changed files with 369 additions and 5 deletions

15
app/relations/pages.rb Normal file
View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
module Adamantium
module Relations
class Pages < ROM::Relation[:sql]
schema :pages, infer: true
auto_struct(true)
def published
where(self[:published_at] <= Time.now)
end
end
end
end

11
app/repos/page_repo.rb Normal file
View File

@@ -0,0 +1,11 @@
module Adamantium
module Repos
class PageRepo < Adamantium::Repo[:pages]
def fetch!(slug:)
pages
.published
.where(slug: slug).one!
end
end
end
end

View File

@@ -2,6 +2,7 @@
- context.content_for(:highlight_code, false)
article class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 prose-em:font-bold prose-em:not-italic prose-em:bg-blue-600 prose-em:px-1 prose-em:rounded prose-a:text-blue-600 prose-a:dark:text-indigo-300 prose-a:p-0.5 prose-a:rounded-sm prose-a:no-underline hover:prose-a:underline prose-em:text-blue-100"
h1= page_name
== page_content
div class="max-w-screen-md mx-auto border-t border-solid border-gray-200 dark:border-gray-600"

View File

@@ -2,15 +2,21 @@ module Adamantium
module Views
module Pages
class Show < Adamantium::View
include Deps[renderer: "renderers.markdown"]
include Deps["repos.page_repo", renderer: "renderers.markdown"]
expose :page_content do |slug:|
markdown_content = File.read("app/content/pages/#{slug}.md")
renderer.call(content: markdown_content)
expose :page_content do |page|
renderer.call(content: page.content)
rescue Errno::ENOENT
renderer.call(content: "## Page not found")
end
expose :page_name do |page|
page.name
end
private_expose :page do |slug:|
page_repo.fetch!(slug: slug)
end
end
end
end