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 end
def prefix_emoji def prefix_emoji
name ? "" : "📯" prefix = name ? "" : "📯"
location ? "🗺️" : prefix
end end
def display_title def display_title
@@ -54,8 +55,24 @@ module Adamantium
"#{Hanami.app.settings.micropub_site_url}/post/#{slug}" "#{Hanami.app.settings.micropub_site_url}/post/#{slug}"
end end
def lat
geo[0]
end
def lon
geo[1]
end
private 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) def truncate_html(content, len = 30, at_end = nil)
p = REXML::Parsers::PullParser.new(content) p = REXML::Parsers::PullParser.new(content)
tags = [] tags = []

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
module Adamantium module Adamantium
module Repos module Repos
class PostRepo < Adamantium::Repo[:posts] class PostRepo < Adamantium::Repo[:posts]
Sequel.extension :pg_json_ops
commands update: :by_pk commands update: :by_pk
def create(post_attrs) def create(post_attrs)
@@ -52,8 +53,30 @@ module Adamantium
end end
def post_listing(limit: nil) 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 posts
.where(post_type: "post") .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 .published
.combine(:tags) .combine(:tags)
.order(Sequel.desc(:published_at)) .order(Sequel.desc(:published_at))
@@ -73,7 +96,7 @@ module Adamantium
def for_rss def for_rss
posts posts
.where(post_type: "post") .where(post_type: "post", location: nil)
.published .published
.combine(:tags) .combine(:tags)
.order(Sequel.desc(:published_at)) .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" div class="e-content"
== post.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="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" 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 = 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" 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 == 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 == render :tags, tags: post.tags
p class="text-sm text-blue-400" 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

View File

@@ -6,6 +6,7 @@ module Adamantium
class App < Hanami::App class App < Hanami::App
config.actions.content_security_policy[:script_src] += " https://gist.github.com" config.actions.content_security_policy[:script_src] += " https://gist.github.com"
config.actions.content_security_policy[:script_src] += " *.dnitza.com" config.actions.content_security_policy[:script_src] += " *.dnitza.com"
config.actions.content_security_policy[:media_src] += " https://dnitza.com"
config.actions.content_security_policy[:script_src] += " https://unpkg.com/htmx.org@1.8.4" config.actions.content_security_policy[:script_src] += " https://unpkg.com/htmx.org@1.8.4"
config.actions.content_security_policy[:connect_src] += " https://stats.dnitza.com/api/event" config.actions.content_security_policy[:connect_src] += " https://stats.dnitza.com/api/event"

View File

@@ -23,6 +23,8 @@ module Adamantium
get "/bookmarks/metadata/:id", to: "bookmarks.metadata" get "/bookmarks/metadata/:id", to: "bookmarks.metadata"
get "/bookmark/:slug", to: "bookmarks.show" get "/bookmark/:slug", to: "bookmarks.show"
get "/places", to: "places.index"
get "/tagged/:slug", to: "tags.show" get "/tagged/:slug", to: "tags.show"
get "/key", to: "key.show" if Hanami.app.settings.micropub_pub_key get "/key", to: "key.show" if Hanami.app.settings.micropub_pub_key

View File

@@ -0,0 +1,9 @@
# frozen_string_literal: true
ROM::SQL.migration do
change do
alter_table :posts do
add_column :location, :text, default: nil
end
end
end

View File

@@ -49,6 +49,7 @@ module Adamantium
new_params[:slug] = params[:slug] || params["mp-slug"] new_params[:slug] = params[:slug] || params["mp-slug"]
new_params[:syndicate_to] = params[:properties][:"mp-syndicate-to"] || [] new_params[:syndicate_to] = params[:properties][:"mp-syndicate-to"] || []
new_params[:photos] = params[:properties][:photo] || [] new_params[:photos] = params[:properties][:photo] || []
new_params[:location] = params[:properties][:location]
else else
new_params[:syndicate_to] = params[:"mp-syndicate-to"] || [] new_params[:syndicate_to] = params[:"mp-syndicate-to"] || []
new_params[:name] = params[:name] new_params[:name] = params[:name]
@@ -56,6 +57,7 @@ module Adamantium
new_params[:published_at] = (params[:"post-status"] == "draft") ? nil : publish_time new_params[:published_at] = (params[:"post-status"] == "draft") ? nil : publish_time
new_params[:category] = params[:category] || [] new_params[:category] = params[:category] || []
new_params[:photos] = params[:photo] || [] new_params[:photos] = params[:photo] || []
new_params[:location] = params[:location]
content = if params[:content] content = if params[:content]
if params[:content].is_a?(Hash) && params[:content][:html] if params[:content].is_a?(Hash) && params[:content][:html]

View File

@@ -983,6 +983,10 @@ video {
grid-column: span 5 / span 5; grid-column: span 5 / span 5;
} }
.m-4 {
margin: 1rem;
}
.mx-auto { .mx-auto {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
@@ -1024,6 +1028,10 @@ video {
margin-top: 0px; margin-top: 0px;
} }
.mr-4 {
margin-right: 1rem;
}
.inline { .inline {
display: inline; display: inline;
} }
@@ -1040,6 +1048,10 @@ video {
height: 4rem; height: 4rem;
} }
.h-48 {
height: 12rem;
}
.w-36 { .w-36 {
width: 9rem; width: 9rem;
} }
@@ -1060,6 +1072,10 @@ video {
width: 1rem; width: 1rem;
} }
.w-48 {
width: 12rem;
}
.max-w-prose { .max-w-prose {
max-width: 65ch; max-width: 65ch;
} }
@@ -1149,6 +1165,11 @@ video {
border-color: transparent; border-color: transparent;
} }
.border-gray-200 {
--tw-border-opacity: 1;
border-color: rgb(229 231 235 / var(--tw-border-opacity));
}
.bg-blue-400 { .bg-blue-400 {
--tw-bg-opacity: 1; --tw-bg-opacity: 1;
background-color: rgb(96 165 250 / var(--tw-bg-opacity)); background-color: rgb(96 165 250 / var(--tw-bg-opacity));
@@ -1167,6 +1188,11 @@ video {
fill: #dbeafe; fill: #dbeafe;
} }
.object-cover {
-o-object-fit: cover;
object-fit: cover;
}
.p-1 { .p-1 {
padding: 0.25rem; padding: 0.25rem;
} }
@@ -1433,6 +1459,16 @@ h1, h2, h3, h4, h5, h6, h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
fill: #60a5fa; fill: #60a5fa;
} }
.hover\:object-fill:hover {
-o-object-fit: fill;
object-fit: fill;
}
.hover\:object-scale-down:hover {
-o-object-fit: scale-down;
object-fit: scale-down;
}
.hover\:text-blue-100:hover { .hover\:text-blue-100:hover {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgb(219 234 254 / var(--tw-text-opacity)); color: rgb(219 234 254 / var(--tw-text-opacity));
@@ -1472,6 +1508,10 @@ h1, h2, h3, h4, h5, h6, h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
text-decoration-line: underline; text-decoration-line: underline;
} }
.hover\:opacity-80:hover {
opacity: 0.8;
}
.prose-a\:rounded-sm :is(:where(a):not(:where([class~="not-prose"] *))) { .prose-a\:rounded-sm :is(:where(a):not(:where([class~="not-prose"] *))) {
border-radius: 0.125rem; border-radius: 0.125rem;
} }

View File

@@ -19,7 +19,8 @@ RSpec.describe Adamantium::Syndication::Mastodon do
published_at: Time.now, published_at: Time.now,
post_type: "post", post_type: "post",
syndicate_to: [], syndicate_to: [],
photos: [] photos: [],
location: nil
) )
} }