Add places

This commit is contained in:
2023-02-19 19:05:57 +11:00
parent 9b4fd437cd
commit 23c702b2b9
16 changed files with 143 additions and 3 deletions

View File

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

View File

@@ -26,7 +26,8 @@ module Adamantium
end
def prefix_emoji
name ? "" : "📯"
prefix = name ? "" : "📯"
location ? "🗺️" : prefix
end
def display_title
@@ -54,8 +55,24 @@ module Adamantium
"#{Hanami.app.settings.micropub_site_url}/post/#{slug}"
end
def lat
geo[0]
end
def lon
geo[1]
end
private
# e.g. geo:-37.75188,144.90417;u=35
def geo
loc = location.split(":")[1]
p = loc.split(";")[0]
p.split(",")
end
def truncate_html(content, len = 30, at_end = nil)
p = REXML::Parsers::PullParser.new(content)
tags = []

View File

@@ -12,6 +12,7 @@ module Adamantium
attribute :post_type, Types::Coercible::String
attribute :syndicate_to, Types::Array.of(Types::Coercible::String)
attribute :photos, Types::Array.of(Types::Hash)
attribute :location, Types::Coercible::String.optional
end
end
end

View File

@@ -11,6 +11,7 @@ module Adamantium
attribute :post_type, Types::Coercible::String
attribute :syndicate_to, Types::Array.of(Types::Coercible::String)
attribute :photos, Types::Array.of(Types::Hash)
attribute :location, Types::Coercible::String.optional
end
end
end

View File

@@ -1,6 +1,7 @@
module Adamantium
module Repos
class PostRepo < Adamantium::Repo[:posts]
Sequel.extension :pg_json_ops
commands update: :by_pk
def create(post_attrs)
@@ -52,8 +53,30 @@ module Adamantium
end
def post_listing(limit: nil)
posts
.where(post_type: "post", location: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def photo_listing(limit: nil)
posts
.where(post_type: "post")
.where(Sequel[:photos].pg_json.array_length > 0)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def places_listing(limit: nil)
posts
.where(post_type: "post")
.exclude(location: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
@@ -73,7 +96,7 @@ module Adamantium
def for_rss
posts
.where(post_type: "post")
.where(post_type: "post", location: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))

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 Places
div class="mb-12 max-w-prose mx-auto"
- places.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

@@ -14,6 +14,9 @@ article class="h-entry"
div class="e-content"
== post.content
- if post.location
img class="shadow-solid shadow-pink-100 dark:shadow-pink-200 rounded mb-4" src="https://api.mapbox.com/styles/v1/dnitza/cleb2o734000k01pbifls5620/static/#{post.lat},#{post.lon},14,0/300x400@2x?access_token=pk.eyJ1IjoiZG5pdHphIiwiYSI6ImNsZWIzOHFmazBkODIzdm9kZHgxdDF4ajQifQ.mSneE-1SKeju8AOz5gp4BQ"
div class="mb-4 max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"
div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex"

View File

@@ -0,0 +1,2 @@
a href="#{post.permalink}"
img class="rounded object-cover hover:opacity-80 h-48 w-48 mr-4 mb-4" src="#{post.photos[0]["value"]}" alt="#{post.photos[0]["alt"]}"

View File

@@ -4,6 +4,8 @@ div class="mb-8 h-entry"
= post.display_title
div class="e-content p-name text-base prose prose-ul:list-none prose-ul:pl-0 prose-li:pl-0 text-gray-800 dark:text-gray-200"
== post.excerpt
-if post.location
img src="https://api.mapbox.com/styles/v1/dnitza/cleb2o734000k01pbifls5620/static/#{post.lat},#{post.lon},14,0/50x50@2x?access_token=pk.eyJ1IjoiZG5pdHphIiwiYSI6ImNsZWIzOHFmazBkODIzdm9kZHgxdDF4ajQifQ.mSneE-1SKeju8AOz5gp4BQ"
== render :tags, tags: post.tags
p class="text-sm text-blue-400"

15
app/views/places/index.rb Normal file
View File

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