Add statuses

This commit is contained in:
2023-02-27 21:02:38 +11:00
parent 23d03d2be1
commit f1c3263922
10 changed files with 81 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ gem "pinboard", git: "https://github.com/dnitza/pinboard", branch: "master"
gem "ogpr"
gem "ruby-filemagic", git: "https://github.com/dnitza/ruby-filemagic", branch: "master"
gem "webmention"
gem "sanitize"
group :cli, :development do
gem "hanami-reloader"

View File

@@ -56,6 +56,7 @@ GEM
sshkit (~> 1.3)
coderay (1.1.3)
concurrent-ruby (1.2.0)
crass (1.0.6)
database_cleaner-core (2.0.1)
database_cleaner-sequel (2.0.2)
database_cleaner-core (~> 2.0.0)
@@ -339,6 +340,9 @@ GEM
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
sanitize (6.0.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
sequel (5.65.0)
shellany (0.0.1)
slim (5.0.0)
@@ -405,6 +409,7 @@ DEPENDENCIES
rom-factory
rom-sql
ruby-filemagic!
sanitize
slim
standardrb
timecop

View File

@@ -0,0 +1,12 @@
module Adamantium
module Actions
module Statuses
class Index < Action
include Deps["views.statuses.index"]
def handle(req, res)
res.render index
end
end
end
end
end

View File

@@ -3,6 +3,7 @@
# auto_register: false
require "rexml/parsers/pullparser"
require "sanitize"
module Adamantium
module Decorators
@@ -58,6 +59,10 @@ module Adamantium
photos? ? "<div>#{photos.map { |p| "<img src='#{p["value"]}'/>" }.join("")} #{content}</div>" : content
end
def raw_content
Sanitize.fragment(content)
end
def excerpt
truncate_html(content, 140, true)
end

View File

@@ -55,6 +55,7 @@ module Adamantium
def post_listing(limit: nil)
posts
.where(post_type: "post", location: nil)
.exclude(name: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
@@ -93,6 +94,25 @@ module Adamantium
query ? base.where(Sequel.ilike(:name, "%#{query}%")).to_a : base.to_a
end
def statuses_listing(limit: nil)
posts
.where(post_type: "post", name: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def latest_status
posts
.where(name: nil)
.published
.order(Sequel.desc(:published_at))
.limit(1)
.one
end
def last_location
posts
.where(post_type: "checkin")

View File

@@ -4,9 +4,17 @@ div class="h-card prose dark:prose-invert mb-12 max-w-prose mx-auto text-gray-80
div class="mb-8 max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"
div class="mb-12 p-2 grid grid-cols-7 gap-4 min-h-16 max-w-prose mx-auto bg-fuchsia-100 dark:bg-fuchsia-800 dark:text-gray-200 rounded"
div class="col-span-6 text-left"
a class="block my-auto hover:underline decoration-wavy" href=latest_status.permalink
== "#{latest_status.raw_content}"
a class="col-span-1 px-2 text-center transition-colors rounded bg-fuchsia-50 hover:bg-fuchsia-200 dark:bg-fuchsia-900 dark:hover:bg-fuchsia-700 inline-block grid content-center max-h-12 my-auto" href="/statuses"
p See all
div class="mb-4 flex max-w-prose mx-auto"
h2 class="text-l text-gray-600 dark:text-gray-200" Recent posts
a class="text-right flex-1 text-blue-400" href="/posts" See all &rarr;
h2 class="text-l" Posts
a class="text-right flex-1 text-blue-400 dark:text-blue-200" href="/posts" See all &rarr;
div class="mb-12 max-w-prose mx-auto"
- posts.each do |post|

View File

@@ -0,0 +1,8 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Statuses
div class="h-feed mb-12 max-w-prose mx-auto"
- posts.each do |post|
== render :post, post: post
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"

View File

@@ -22,6 +22,10 @@ module Adamantium
end
end
expose :latest_status do
Decorators::Posts::Decorator.new(post_repo.latest_status)
end
expose :last_location do
Decorators::Posts::Decorator.new(post_repo.last_location)
end

View File

@@ -0,0 +1,15 @@
module Adamantium
module Views
module Statuses
class Index < Adamantium::View
include Deps["repos.post_repo"]
expose :posts do
post_repo.statuses_listing.map do |post|
Decorators::Posts::Decorator.new(post)
end
end
end
end
end
end

View File

@@ -25,6 +25,7 @@ module Adamantium
get "/photos", to: "photos.index"
get "/places", to: "places.index"
get "/statuses", to: "statuses.index"
get "/tagged/:slug", to: "tags.show"