Vendor htmx 2.0.6 (#57)

This commit is contained in:
2025-07-04 18:18:13 -04:00
parent e8953d6072
commit 87fbb1a8c7
5 changed files with 34 additions and 14 deletions
+28 -11
View File
@@ -5,11 +5,12 @@ open Giraffe
open Microsoft.AspNetCore.Http
open MyWebLog
/// Module to resolve routes that do not match any other known route (web blog content)
/// Module to resolve routes that do not match any other known route (web blog content)
module CatchAll =
open System.IO
open MyWebLog.ViewModels
/// Sequence where the first returned value is the proper handler for the link
let private deriveAction (ctx: HttpContext) : HttpHandler seq =
let webLog = ctx.WebLog
@@ -22,7 +23,21 @@ module CatchAll =
let await it = (Async.AwaitTask >> Async.RunSynchronously) it
seq {
debug (fun () -> $"Considering URL {textLink}")
// Home page directory without the directory slash
let staticFileName =
[ ctx.GetWebHostEnvironment().ContentRootPath
"wwwroot"
if textLink.Length > 1 then textLink[1..] else textLink ]
|> String.concat (string Path.DirectorySeparatorChar)
match File.Exists staticFileName with
| true ->
debug (fun () -> $"File {textLink} is a static file")
yield
File.GetLastWriteTimeUtc staticFileName
|> System.DateTimeOffset
|> Some
|> streamFile true staticFileName None
| false -> ()
// Home page directory without the directory slash
if textLink = "" then yield redirectTo true (webLog.RelativeUrl Permalink.Empty)
let permalink = Permalink textLink[1..]
// Current post
@@ -52,7 +67,7 @@ module CatchAll =
match Feed.deriveFeedType ctx textLink with
| Some (feedType, postCount) ->
debug (fun () -> "Found RSS feed")
yield Feed.generate feedType postCount
yield Feed.generate feedType postCount
| None -> ()
// Post differing only by trailing slash
let altLink =
@@ -84,13 +99,15 @@ module CatchAll =
}
// GET {all-of-the-above}
let route : HttpHandler = fun next ctx ->
match deriveAction ctx |> Seq.tryHead with Some handler -> handler next ctx | None -> Error.notFound next ctx
let route : HttpHandler = fun next ctx -> task {
match deriveAction ctx |> Seq.tryHead with
| Some handler -> return! handler next ctx
| None -> return None // Error.notFound next ctx
}
/// Serve theme assets
module Asset =
// GET /theme/{theme}/{**path}
let serve (urlParts: string seq) : HttpHandler = fun next ctx -> task {
let path = urlParts |> Seq.skip 1 |> Seq.head
@@ -228,7 +245,7 @@ let router : HttpHandler = choose [
])
GET_HEAD >=> routexp "/category/(.*)" Post.pageOfCategorizedPosts
GET_HEAD >=> routef "/page/%i" Post.pageOfPosts
GET_HEAD >=> routef "/page/%i/" Post.redirectToPageOfPosts
GET_HEAD >=> routef "/page/%i/" Post.redirectToPageOfPosts
GET_HEAD >=> routexp "/tag/(.*)" Post.pageOfTaggedPosts
GET_HEAD >=> routexp "/themes/(.*)" Asset.serve
GET_HEAD >=> routexp "/upload/(.*)" Upload.serve
@@ -242,7 +259,7 @@ let router : HttpHandler = choose [
]
])
GET_HEAD >=> CatchAll.route
Error.notFound
//Error.notFound
]
/// Wrap a router in a sub-route