WIP on adding htmax option (#59)

This commit is contained in:
2026-07-05 17:54:36 -04:00
parent 7c588662d2
commit 9d2277ab32
10 changed files with 81 additions and 15 deletions
+7 -4
View File
@@ -5,9 +5,7 @@ open System
open System.IO
open System.Web
open DotLiquid
open Giraffe.ViewEngine
open MyWebLog.ViewModels
open MyWebLog.Views
/// Extensions on the DotLiquid Context object
type Context with
@@ -158,8 +156,13 @@ type PageFootTag() =
// spacer
let s = " "
if webLog.AutoHtmx then
result.WriteLine $"{s}{RenderView.AsString.htmlNode Htmx.Script.local}"
match webLog.AutoHtmx with
| NoAutoHtmx -> None
| AutoHtmx -> (Permalink >> Some) Giraffe.Htmx.Common.StaticAssetUrl.htmx[1..]
| AutoHtmax -> (Permalink >> Some) Giraffe.Htmx.Common.StaticAssetUrl.htmax[1..]
|> function
| Some url -> result.WriteLine $"""{s}<script src="{context.WebLog.RelativeUrl url}"></script>"""
| None -> ()
if assetExists "script.js" webLog then
result.WriteLine $"""{s}<script src="{ThemeAssetFilter.ThemeAsset(context, "script.js")}"></script>"""
+3 -3
View File
@@ -240,9 +240,9 @@ let main args =
let _ = app.UseForwardedHeaders()
(app.Services.GetRequiredService<IConfiguration>().GetSection "CanonicalDomains").Value
|> isNotNull
|> function true -> app.UseCanonicalDomains() |> ignore | false -> ()
match (app.Services.GetRequiredService<IConfiguration>().GetSection "CanonicalDomains").Value with
| null -> ()
| _ -> app.UseCanonicalDomains() |> ignore
app .UseCookiePolicy(CookiePolicyOptions(MinimumSameSitePolicy = SameSiteMode.Strict))
.UseMiddleware<WebLogMiddleware>()
+8 -2
View File
@@ -255,10 +255,16 @@ let parser =
it.RegisterEmptyTag("page_foot",
fun writer encoder context ->
let webLog = context.App.WebLog
if webLog.AutoHtmx then
context.App.WebLog.RelativeUrl(Permalink StaticAssetUrl.htmx[1..])
match webLog.AutoHtmx with
| NoAutoHtmx -> None
| AutoHtmx -> (Permalink >> Some) StaticAssetUrl.htmx[1..]
| AutoHtmax -> (Permalink >> Some) StaticAssetUrl.htmax[1..]
|> function
| Some url ->
context.App.WebLog.RelativeUrl url
|> sprintf "%s<script src=\"%s\"></script>" s
|> writer.WriteLine
| None -> ()
if assetExists "script.js" webLog then
themeAsset (StringValue "script.js") context
|> sprintf "%s<script src=\"%s\"></script>" s