Refactor app in to its own slice

This commit is contained in:
2024-02-17 10:40:36 +11:00
parent b809b132d3
commit a6078f882e
161 changed files with 16176 additions and 193 deletions

View File

@@ -92,10 +92,10 @@ end
namespace :tailwind do
task :watch do
system("npx tailwindcss -i ./app/assets/css/app.css -o ./app/assets/builds/app.css --watch")
system("npx tailwindcss -i ./slices/main/assets/css/app.css -o ./slices/main/assets/builds/app.css --watch")
end
task :build do
system("npx tailwindcss -i ./app/assets/css/app.css -o ./app/assets/builds/app.css --minify")
system("npx tailwindcss -i ./slices/main/assets/css/app.css -o ./slices/main/assets/builds/app.css --minify")
end
end

View File

@@ -2,7 +2,7 @@
require "hanami/boot"
use Rack::Static, urls: ["/assets", "/media"], root: "public"
use Rack::Static, urls: ["/assets", "/media", "/fonts"], root: "public", cascade: true
raise StandardError.new("No secret key") unless ENV["SESSION_SECRET"]

View File

@@ -33,6 +33,7 @@ module Adamantium
"syndication.mastodon",
"syndication.blue_sky",
"syndication.raindrop",
"view_cache.cacher",
"renderers.markdown"
]
end

View File

@@ -63,7 +63,7 @@ server {
# Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
# BUT there's a chance it could break the ajax calls.
location ~* \.(ico|css|gif|jpe?g|png|js|ttf)(\?[0-9]+)?$ {
location ~* \.(ico|css|gif|jpe?g|png|js)(\?[0-9]+)?$ {
expires max;
break;
}

View File

@@ -6,59 +6,9 @@ module Adamantium
class Routes < Hanami::Routes
use Hanami::Middleware::BodyParser, [:form, :json]
slice :main, at: "/"
slice :admin, at: "/admin"
slice :micropub, at: "/micropub"
root to: "site.home"
get "/post/top_tracks/:slug", to: "posts.top_tracks"
get "/post/:slug", to: "posts.show"
get "/posts", to: "posts.index"
# get "/posts/archive", to: "posts.archive"
get "/posts/archive/:year", to: "posts.archive"
get "/bookmarks", to: "bookmarks.index"
get "/bookmarks/metadata/:id", to: "bookmarks.metadata"
get "/bookmark/:slug", to: "bookmarks.show"
get "/photos", to: "photos.index"
get "/places", to: "places.index"
get "/places/map", to: "places.map_page"
get "/statuses", to: "statuses.index"
get "/tags", to: "tags.index"
get "/tagged/:slug", to: "tags.show"
get "/key", to: "key.show" if Hanami.app.settings.micropub_pub_key
get "/feeds/rss", to: "feeds.rss"
get "/feeds/statuses_rss", to: "feeds.statuses_rss"
get "/more", to: "more.index"
get "/hikes", to: "workouts.index"
post "/workouts", to: "workouts.create"
get "/movies", to: "movies.index"
get "/blogroll", to: "blogroll.index"
get "/blogroll/list", to: "blogroll.list"
get "/blogroll/opml", to: "blogroll.opml"
get "/recently_played", to: "recently_played.index"
get "/:slug", to: "pages.show"
get "/trips", to: "trips.index"
get "/trips/:id", to: "trips.show"
get "/podcasts", to: "podcasts.index"
get "/bookshelf", to: "books.index"
get "/timemachine/:year/:month/:day", to: "timemachine.show"
redirect "deploying-a-hanami-app-to-fly-io", to: "/post/deploying-a-hanami-20-app-to-flyio"
redirect "deploying-a-hanami-app-to-fly-io/", to: "/post/deploying-a-hanami-20-app-to-flyio"
slice :admin, at: "/admin"
end
end

View File

@@ -1,4 +1,4 @@
/* app/assets/builds/app.css */
/* slices/main/assets/builds/app.css */
*,
::before,
::after {
@@ -4097,10 +4097,6 @@ video {
--tw-text-opacity: 1;
color: rgb(217 119 6 / var(--tw-text-opacity));
}
.text-blue-100 {
--tw-text-opacity: 1;
color: rgb(219 234 254 / var(--tw-text-opacity));
}
.text-blue-200 {
--tw-text-opacity: 1;
color: rgb(191 219 254 / var(--tw-text-opacity));
@@ -4279,10 +4275,6 @@ video {
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
}
.text-green-100 {
--tw-text-opacity: 1;
color: rgb(220 252 231 / var(--tw-text-opacity));
}
.text-green-400 {
--tw-text-opacity: 1;
color: rgb(74 222 128 / var(--tw-text-opacity));
@@ -4421,10 +4413,6 @@ video {
--tw-text-opacity: 1;
color: rgb(49 46 129 / var(--tw-text-opacity));
}
.text-orange-100 {
--tw-text-opacity: 1;
color: rgb(255 237 213 / var(--tw-text-opacity));
}
.text-orange-400 {
--tw-text-opacity: 1;
color: rgb(251 146 60 / var(--tw-text-opacity));

View File

@@ -5499,11 +5499,6 @@ video {
color: rgb(217 119 6 / var(--tw-text-opacity));
}
.text-blue-100 {
--tw-text-opacity: 1;
color: rgb(219 234 254 / var(--tw-text-opacity));
}
.text-blue-200 {
--tw-text-opacity: 1;
color: rgb(191 219 254 / var(--tw-text-opacity));
@@ -5737,11 +5732,6 @@ video {
color: rgb(17 24 39 / var(--tw-text-opacity));
}
.text-green-100 {
--tw-text-opacity: 1;
color: rgb(220 252 231 / var(--tw-text-opacity));
}
.text-green-400 {
--tw-text-opacity: 1;
color: rgb(74 222 128 / var(--tw-text-opacity));
@@ -5925,11 +5915,6 @@ video {
color: rgb(49 46 129 / var(--tw-text-opacity));
}
.text-orange-100 {
--tw-text-opacity: 1;
color: rgb(255 237 213 / var(--tw-text-opacity));
}
.text-orange-400 {
--tw-text-opacity: 1;
color: rgb(251 146 60 / var(--tw-text-opacity));

149
public/assets/main/app.js Normal file
View File

@@ -0,0 +1,149 @@
(() => {
// slices/main/assets/js/gallery.js
function md_gallery(config) {
var config = config || {}, list_type = config.list_type || "ul", class_name = config.class_name || "gallery", tag_type = config.tag_type || "div";
function find_lists(list_type2) {
var lists = document.getElementsByTagName(list_type2), matching_lists = [];
for (var i = 0; i < lists.length; i++) {
var list_elements = lists[i].children;
var total_matches = 0;
for (var c = 0; c < list_elements.length; c++) {
if (!list_elements[c].textContent.length && (list_elements[c].firstChild.tagName == "A" || list_elements[c].firstChild.tagName == "IMG") && (!list_elements[c].firstChild.firstChild || list_elements[c].firstChild.firstChild && list_elements[c].firstChild.firstChild.tagName == "IMG")) {
total_matches++;
}
}
if (total_matches == list_elements.length) {
matching_lists[matching_lists.length] = lists[i];
}
}
return matching_lists;
}
function prepend_tag(img_lists, list_tag, prepend_tag2, class_name2) {
for (var i = 0; i < img_lists.length; i++) {
add_anchor(img_lists[i]);
wrap_tag(img_lists[i], prepend_tag2, class_name2, null, true);
strip_tag(img_lists[i], "li");
strip_tag(img_lists[i].parentNode, list_tag);
}
}
function append_caption(el) {
if (el.tagName == "A" && el.firstChild.tagName == "IMG" && el.firstChild.hasAttribute("alt") && el.firstChild.getAttribute("alt").length > 0 || el.tagName == "IMG" && el.hasAttribute("alt") && el.getAttribute("alt").length > 0) {
var caption = document.createElement("figcaption");
try {
caption.textContent = el.firstChild.getAttribute("alt");
el.appendChild(caption);
} catch (e) {
caption.textContent = el.getAttribute("alt");
el.parentNode.appendChild(caption);
}
}
}
function strip_tag(el, tag_type2) {
var start_tag_regex = new RegExp("<" + tag_type2 + ">", "gi");
var end_tag_regex = new RegExp("</" + tag_type2 + ">", "gi");
el.innerHTML = el.innerHTML.replace(start_tag_regex, "").replace(end_tag_regex, "");
}
function add_figure_tags(img_list) {
var list_elements = img_list.children;
for (var i = 0; i < list_elements.length; i++) {
append_caption(list_elements[i].firstChild);
wrap_tag(list_elements[i], "figure");
}
}
function add_anchor(img_list) {
var list_elements = img_list.children;
for (var i = 0; i < list_elements.length; i++) {
let img = list_elements[i].getElementsByTagName("img")[0];
let src = img.getAttribute("src");
let alt = img.getAttribute("alt");
wrap_tag(
list_elements[i],
"a",
"hover:cursor-pointer",
"$dispatch('img-modal', { imgModalSrc: '" + src + "', imgModalDesc: '" + alt + "' })",
false
);
}
}
function wrap_tag(el, tag_type2, class_name2, click, root) {
var wrap = document.createElement(tag_type2);
if (root) {
wrap.setAttribute("x-data", "{}");
}
if (class_name2) {
wrap.setAttribute("class", class_name2);
}
if (click) {
wrap.setAttribute("x-on:click.prevent", click);
wrap.setAttribute("href", "#");
}
el.parentNode.replaceChild(wrap, el);
wrap.appendChild(el);
}
var found_img_lists = find_lists(list_type);
if (found_img_lists.length) {
prepend_tag(found_img_lists, list_type, tag_type, class_name);
}
}
// slices/main/assets/js/app.js
(function() {
document.addEventListener("DOMContentLoaded", function() {
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (event) => {
localStorage.setItem("_x_darkMode", event.matches ? true : false);
});
if (window.hljs !== void 0) {
window.hljs.highlightAll();
}
const times = document.querySelectorAll("time");
times.forEach((time) => {
const oldDtime = Date.parse(time.dateTime);
time.innerHTML = new Date(oldDtime).toLocaleDateString(navigator.language, { weekday: "long", year: "numeric", month: "short", day: "numeric" });
md_gallery({
"class_name": "grid gap-4 grid-cols-2 prose-img:m-0"
});
const mediaForm = document.getElementById("media_form");
if (mediaForm !== null) {
htmx.on("#media_form", "htmx:xhr:progress", function(evt) {
htmx.find("#progress").setAttribute("value", evt.detail.loaded / evt.detail.total * 100);
});
}
});
const videos = document.querySelectorAll("video");
videos.forEach((video) => {
video.addEventListener("click", () => {
const isPaused = video.paused;
video[isPaused ? "play" : "pause"]();
video.classList.toggle("u-none", !isPaused);
});
});
const mapContainer = document.getElementById("map");
const goBack = document.getElementById("go-back");
if (mapContainer !== null) {
if (goBack !== null) {
document.getElementById("go-back").addEventListener("click", () => {
history.back();
});
}
mapboxgl.accessToken = "pk.eyJ1IjoiZG5pdHphIiwiYSI6ImNsZWIyY3ZzaTE0cjUzdm4xdnZ6czRlYjUifQ.FRETOXYRID6T2IoB7qqRLg";
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
maxZoom: 8
});
const markers = JSON.parse(mapContainer.dataset["markers"]);
const bounds = new mapboxgl.LngLatBounds(markers[0], markers[0]);
for (var i = 0; i < markers.length; i++) {
bounds.extend(markers[i]);
}
map.fitBounds(bounds, { padding: 60 });
for (var i = 0; i < markers.length; i++) {
const marker = markers[i];
const el = document.createElement("div");
el.className = "map-marker";
new mapboxgl.Marker(el).setLngLat(marker).addTo(map);
}
}
});
})();
})();

View File

@@ -0,0 +1,26 @@
{
"app.js": {
"url": "/assets/main/app.js"
},
"Figtree-Italic-VariableFont_wght.ttf": {
"url": "/assets/main/Figtree-Italic-VariableFont_wght.ttf"
},
"Figtree-VariableFont_wght.ttf": {
"url": "/assets/main/Figtree-VariableFont_wght.ttf"
},
"JetBrainsMono-VariableFont_wght.ttf": {
"url": "/assets/main/JetBrainsMono-VariableFont_wght.ttf"
},
"Karla-VariableFont_wght.ttf": {
"url": "/assets/main/Karla-VariableFont_wght.ttf"
},
"MontaguSlab-VariableFont_opsz,wght.ttf": {
"url": "/assets/main/MontaguSlab-VariableFont_opsz,wght.ttf"
},
"Rubik-VariableFont_wght.ttf": {
"url": "/assets/main/Rubik-VariableFont_wght.ttf"
},
"app.css": {
"url": "/assets/main/app.css"
}
}

View File

@@ -1,4 +1,4 @@
import "../../../../app/assets/builds/app.css";
import "../../../../slices/main/assets/builds/app.css";
import "../css/app.css";
import TinyMDE from "tiny-markdown-editor";

8
slices/main/action.rb Normal file
View File

@@ -0,0 +1,8 @@
# auto_register: false
# frozen_string_literal: true
module Main
class Action < Adamantium::Action
end
end

View File

@@ -1,6 +1,6 @@
require "time_math"
module Adamantium
module Main
module Actions
module Blogroll
class Index < Action

View File

@@ -1,6 +1,6 @@
require "time_math"
module Adamantium
module Main
module Actions
module Blogroll
class List < Action

View File

@@ -1,6 +1,6 @@
require "time_math"
module Adamantium
module Main
module Actions
module Blogroll
class Opml < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Bookmarks
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Bookmarks
class Metadata < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Bookmarks
class Show < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Books
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Feeds
class Rss < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Feeds
class StatusesRss < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Key
class Show < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module More
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Movies
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Pages
class Show < Action
@@ -7,7 +7,7 @@ module Adamantium
def handle(req, res)
slug = req.params[:slug]
res.status = File.exist?("app/content/pages/#{slug}.md") ? 200 : 404
res.status = File.exist?("slices/main/content/pages/#{slug}.md") ? 200 : 404
res.render show, slug: slug
end
end

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Photos
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Places
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Places
class MapPage < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Podcasts
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Posts
class Archive < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Posts
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Posts
class Show < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Posts
class TopTracks < Action

View File

@@ -1,6 +1,6 @@
require "time_math"
module Adamantium
module Main
module Actions
module RecentlyPlayed
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Site
class Home < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Statuses
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Tags
class Index < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Tags
class Show < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Timemachine
class Show < Action

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
module Adamantium
module Main
module Actions
module Trips
class Index < Adamantium::Action

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
module Adamantium
module Main
module Actions
module Trips
class Show < Adamantium::Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Workouts
class Create < Action

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Actions
module Workouts
class Index < Action

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,55 @@
module Main
class Routes < Hanami::Routes
root to: "site.home"
get "/post/top_tracks/:slug", to: "posts.top_tracks"
get "/post/:slug", to: "posts.show"
get "/posts", to: "posts.index"
# get "/posts/archive", to: "posts.archive"
get "/posts/archive/:year", to: "posts.archive"
get "/bookmarks", to: "bookmarks.index"
get "/bookmarks/metadata/:id", to: "bookmarks.metadata"
get "/bookmark/:slug", to: "bookmarks.show"
get "/photos", to: "photos.index"
get "/places", to: "places.index"
get "/places/map", to: "places.map_page"
get "/statuses", to: "statuses.index"
get "/tags", to: "tags.index"
get "/tagged/:slug", to: "tags.show"
get "/key", to: "key.show" if Hanami.app.settings.micropub_pub_key
get "/feeds/rss", to: "feeds.rss"
get "/feeds/statuses_rss", to: "feeds.statuses_rss"
get "/more", to: "more.index"
get "/hikes", to: "workouts.index"
post "/workouts", to: "workouts.create"
get "/movies", to: "movies.index"
get "/blogroll", to: "blogroll.index"
get "/blogroll/list", to: "blogroll.list"
get "/blogroll/opml", to: "blogroll.opml"
get "/recently_played", to: "recently_played.index"
get "/:slug", to: "pages.show"
get "/trips", to: "trips.index"
get "/trips/:id", to: "trips.show"
get "/podcasts", to: "podcasts.index"
get "/bookshelf", to: "books.index"
get "/timemachine/:year/:month/:day", to: "timemachine.show"
redirect "deploying-a-hanami-app-to-fly-io", to: "/post/deploying-a-hanami-20-app-to-flyio"
redirect "deploying-a-hanami-app-to-fly-io/", to: "/post/deploying-a-hanami-20-app-to-flyio"
end
end

View File

@@ -2,7 +2,7 @@
# auto_register: false
module Adamantium
module Main
module Decorators
module Bookmarks
class Decorator < SimpleDelegator

View File

@@ -2,7 +2,7 @@
# auto_register: false
module Adamantium
module Main
module Decorators
module Books
class Decorator < SimpleDelegator

View File

@@ -2,7 +2,7 @@
# auto_register: false
module Adamantium
module Main
module Decorators
module Movies
class Decorator < SimpleDelegator

View File

@@ -6,7 +6,7 @@ require "rexml/parsers/pullparser"
require "sanitize"
require "nokogiri"
module Adamantium
module Main
module Decorators
module Posts
class Decorator < SimpleDelegator

View File

@@ -1,6 +1,6 @@
require "httparty"
module Adamantium
module Main
module Queries
module Blogroll
class Index

View File

@@ -1,7 +1,7 @@
require "httparty"
require "jwt"
module Adamantium
module Main
module Queries
module Posts
class RecentlyPlayed

View File

@@ -1,7 +1,7 @@
require "lastfm"
require "time_math"
module Adamantium
module Main
module Queries
module Posts
class TopTracks

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class MovieRepo < Adamantium::Repo[:movies]
def listing

View File

@@ -0,0 +1,19 @@
module Main
module Repos
class PageRepo < Adamantium::Repo[:pages]
def fetch!(slug:)
pages
.published
.where(slug: slug).one!
end
def for_main_nav
pages
.select(:name, :slug, :light_colour, :dark_colour, :published_at)
.published
.where(main_menu: true)
.to_a
end
end
end
end

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class PodcastRepo < Adamantium::Repo[:podcasts]
def listing

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class PodcastScrobbleRepo < Adamantium::Repo[:podcast_scrobbles]
commands :create

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class PostRepo < Adamantium::Repo[:posts]
Sequel.extension :pg_json

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class PostTagRepo < Adamantium::Repo[:post_tags]
def posts_tagged(tag:)

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class TagRepo < Adamantium::Repo[:tags]
def fetch!(slug)

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class TopTrackRepo < Adamantium::Repo[:top_tracks]
def for_post(id:)

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class TripRepo < Adamantium::Repo[:trips]
def fetch!(id)

View File

@@ -1,4 +1,4 @@
module Adamantium
module Main
module Repos
class WorkoutRepo < Adamantium::Repo[:workouts]
def list

View File

@@ -0,0 +1,2 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 There was an error!

View File

@@ -0,0 +1,2 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Not Found!

Some files were not shown because too many files have changed in this diff Show More