Add speculation rules for pre-fetching and rendering

This commit is contained in:
2024-06-16 10:14:57 +10:00
parent be329447ab
commit 98e289744a
4 changed files with 37 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ module Adamantium
class App < Hanami::App
config.actions.content_security_policy[:script_src] += " 'unsafe-eval' https://gist.github.com"
config.actions.content_security_policy[:script_src] += " *.dnitza.com"
config.actions.content_security_policy[:script_src] += " 'inline-speculation-rules' hash-sha256-GSFnYlZ2/GzNMMMe8WYjAF1Xb+IxEi2PZpSLZO+va38="
config.actions.content_security_policy[:script_src] += " https://api.mapbox.com/mapbox-gl-js/v2.9.1/mapbox-gl.js"
config.actions.content_security_policy[:media_src] += " https://dnitza.com"
config.actions.content_security_policy[:script_src] += " https://unpkg.com/htmx.org@1.9.2/dist/htmx.min.js "

View File

@@ -38,6 +38,9 @@ html x-data="{darkMode: $persist(false)}" :class="{'dark' : darkMode === true}"
link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.8.0/styles/github-dark.min.css"
script src="https://unpkg.com/@highlightjs/cdn-assets@11.8.0/highlight.min.js" defer=""
script type="speculationrules"
== context.speculation_rules
meta property="og:title" content="#{context.content_for(:title)}"
meta property="og:type" content="website"
meta property="og:url" content="#{context.content_for(:url)}"

View File

@@ -5,7 +5,6 @@ require "hanami/view"
module Main
class View < Hanami::View
config.default_context = Adamantium::Context.new
config.layouts_dir = "layouts"
config.layout = "app"
config.paths = "slices/main/templates"

View File

@@ -0,0 +1,33 @@
module Main
module Views
class Context < Adamantium::Context
include Deps["repos.page_repo"]
def speculation_rules
{"prerender": [
{
"where": {
"and": [
{"href_matches": "/*"},
]
}
}
],
"prefetch": [
{
"urls": ["bookmarks", "posts", "photos", "statuses", "uses"],
"referrer_policy": "no-referrer"
}
]}.to_json
end
def pages
page_repo.for_main_nav
end
def current_path
request.fullpath
end
end
end
end