Add speculation rules for pre-fetching and rendering
This commit is contained in:
@@ -6,6 +6,7 @@ module Adamantium
|
|||||||
class App < Hanami::App
|
class App < Hanami::App
|
||||||
config.actions.content_security_policy[:script_src] += " 'unsafe-eval' https://gist.github.com"
|
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] += " *.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[: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[:media_src] += " https://dnitza.com"
|
||||||
config.actions.content_security_policy[:script_src] += " https://unpkg.com/htmx.org@1.9.2/dist/htmx.min.js "
|
config.actions.content_security_policy[:script_src] += " https://unpkg.com/htmx.org@1.9.2/dist/htmx.min.js "
|
||||||
|
@@ -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"
|
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 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:title" content="#{context.content_for(:title)}"
|
||||||
meta property="og:type" content="website"
|
meta property="og:type" content="website"
|
||||||
meta property="og:url" content="#{context.content_for(:url)}"
|
meta property="og:url" content="#{context.content_for(:url)}"
|
||||||
|
@@ -5,7 +5,6 @@ require "hanami/view"
|
|||||||
|
|
||||||
module Main
|
module Main
|
||||||
class View < Hanami::View
|
class View < Hanami::View
|
||||||
config.default_context = Adamantium::Context.new
|
|
||||||
config.layouts_dir = "layouts"
|
config.layouts_dir = "layouts"
|
||||||
config.layout = "app"
|
config.layout = "app"
|
||||||
config.paths = "slices/main/templates"
|
config.paths = "slices/main/templates"
|
||||||
|
33
slices/main/views/context.rb
Normal file
33
slices/main/views/context.rb
Normal 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
|
Reference in New Issue
Block a user