Initial commit

This commit is contained in:
2023-01-27 22:55:09 +11:00
commit 833f3ea8b2
130 changed files with 5637 additions and 0 deletions

11
config/app.rb Normal file
View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
require "hanami"
module Adamantium
class App < Hanami::App
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[:connect_src] += " https://stats.dnitza.com/api/event"
end
end

0
config/nginx.conf Normal file
View File

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
Hanami.app.register_provider :param_parser, namespace: true do
start do
register "micropub_post", Adamantium::MicropubRequestParser.new
end
end

View File

@@ -0,0 +1,41 @@
# frozen_string_literal: true
Hanami.app.register_provider :persistence, namespace: true do
prepare do
require "rom-changeset"
require "rom/core"
require "rom/sql"
# TODO(Hanami): As part of built-in rom setup, configure ROM with app inflector
silence_warnings { ROM::Inflector = Hanami.app["inflector"] }
rom_config = ROM::Configuration.new(:sql, target["settings"].database_url)
rom_config.plugin(:sql, relations: :instrumentation) do |plugin_config|
plugin_config.notifications = target["notifications"]
end
rom_config.plugin(:sql, relations: :auto_restrictions)
register "config", rom_config
register "db", rom_config.gateways[:default].connection
end
start do
rom_config = target["persistence.config"]
rom_config.auto_registration(
target.root.join("lib/adamantium/persistence"),
namespace: "Adamantium::Persistence"
)
register "rom", ROM.container(rom_config)
end
define_method(:silence_warnings) do |&block|
orig_verbose = $VERBOSE
$VERBOSE = nil
result = block.call
$VERBOSE = orig_verbose
result
end
end

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
Hanami.app.register_provider :post_utilities, namespace: true do
start do
register "slugify", Adamantium::SlugCreator.new
end
end

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
Hanami.app.register_provider :renderers, namespace: true do
start do
register "markdown", Adamantium::Renderer::Markdown.new
end
end

15
config/puma.rb Normal file
View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
max_threads_count = ENV.fetch("HANAMI_MAX_THREADS", 5)
min_threads_count = ENV.fetch("HANAMI_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
port ENV.fetch("HANAMI_PORT", 2300)
environment ENV.fetch("HANAMI_ENV", "development")
workers ENV.fetch("HANAMI_WEB_CONCURRENCY", 2)
on_worker_boot do
Hanami.shutdown
end
preload_app!

35
config/routes.rb Normal file
View File

@@ -0,0 +1,35 @@
# frozen_string_literal: true
require "hanami/middleware/body_parser"
require "adamantium/middleware/process_params"
module Adamantium
class Routes < Hanami::Routes
use Hanami::Middleware::BodyParser, [:form, :json]
use Adamantium::Middleware::ProcessParams
scope "micropub" do
get "/", to: "site.config"
post "/", to: "posts.handle"
post "/media", to: "media.create"
end
get "/", to: "site.home"
get "/post/:slug", to: "posts.show"
get "/posts", to: "posts.index"
get "/bookmarks", to: "bookmarks.index"
get "/bookmark/:slug", to: "bookmarks.show"
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 "/:slug", to: "pages.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

29
config/settings.rb Normal file
View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
require "adamantium/types"
module Adamantium
class Settings < Hanami::Settings
# Infrastructure
setting :database_url
# Site details
setting :site_name
## ---- Micropub ----
# Site details
setting :micropub_site_id
setting :micropub_site_name
setting :micropub_site_url
# Auth
setting :micropub_pub_key, default: nil
# TODO: add other auth methods here
# Micropub endpoints
setting :micropub_media_endpoint, default: "", constructor: Types::Params::String
setting :micropub_authorization_endpoint
setting :micropub_token_endpoint
end
end