Vendor htmx 2.0.6 (#57)
This commit is contained in:
parent
e8953d6072
commit
87fbb1a8c7
@ -5,11 +5,12 @@ open Giraffe
|
|||||||
open Microsoft.AspNetCore.Http
|
open Microsoft.AspNetCore.Http
|
||||||
open MyWebLog
|
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 =
|
module CatchAll =
|
||||||
|
|
||||||
|
open System.IO
|
||||||
open MyWebLog.ViewModels
|
open MyWebLog.ViewModels
|
||||||
|
|
||||||
/// Sequence where the first returned value is the proper handler for the link
|
/// Sequence where the first returned value is the proper handler for the link
|
||||||
let private deriveAction (ctx: HttpContext) : HttpHandler seq =
|
let private deriveAction (ctx: HttpContext) : HttpHandler seq =
|
||||||
let webLog = ctx.WebLog
|
let webLog = ctx.WebLog
|
||||||
@ -22,7 +23,21 @@ module CatchAll =
|
|||||||
let await it = (Async.AwaitTask >> Async.RunSynchronously) it
|
let await it = (Async.AwaitTask >> Async.RunSynchronously) it
|
||||||
seq {
|
seq {
|
||||||
debug (fun () -> $"Considering URL {textLink}")
|
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)
|
if textLink = "" then yield redirectTo true (webLog.RelativeUrl Permalink.Empty)
|
||||||
let permalink = Permalink textLink[1..]
|
let permalink = Permalink textLink[1..]
|
||||||
// Current post
|
// Current post
|
||||||
@ -52,7 +67,7 @@ module CatchAll =
|
|||||||
match Feed.deriveFeedType ctx textLink with
|
match Feed.deriveFeedType ctx textLink with
|
||||||
| Some (feedType, postCount) ->
|
| Some (feedType, postCount) ->
|
||||||
debug (fun () -> "Found RSS feed")
|
debug (fun () -> "Found RSS feed")
|
||||||
yield Feed.generate feedType postCount
|
yield Feed.generate feedType postCount
|
||||||
| None -> ()
|
| None -> ()
|
||||||
// Post differing only by trailing slash
|
// Post differing only by trailing slash
|
||||||
let altLink =
|
let altLink =
|
||||||
@ -84,13 +99,15 @@ module CatchAll =
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET {all-of-the-above}
|
// GET {all-of-the-above}
|
||||||
let route : HttpHandler = fun next ctx ->
|
let route : HttpHandler = fun next ctx -> task {
|
||||||
match deriveAction ctx |> Seq.tryHead with Some handler -> handler next ctx | None -> Error.notFound next ctx
|
match deriveAction ctx |> Seq.tryHead with
|
||||||
|
| Some handler -> return! handler next ctx
|
||||||
|
| None -> return None // Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
/// Serve theme assets
|
/// Serve theme assets
|
||||||
module Asset =
|
module Asset =
|
||||||
|
|
||||||
// GET /theme/{theme}/{**path}
|
// GET /theme/{theme}/{**path}
|
||||||
let serve (urlParts: string seq) : HttpHandler = fun next ctx -> task {
|
let serve (urlParts: string seq) : HttpHandler = fun next ctx -> task {
|
||||||
let path = urlParts |> Seq.skip 1 |> Seq.head
|
let path = urlParts |> Seq.skip 1 |> Seq.head
|
||||||
@ -228,7 +245,7 @@ let router : HttpHandler = choose [
|
|||||||
])
|
])
|
||||||
GET_HEAD >=> routexp "/category/(.*)" Post.pageOfCategorizedPosts
|
GET_HEAD >=> routexp "/category/(.*)" Post.pageOfCategorizedPosts
|
||||||
GET_HEAD >=> routef "/page/%i" Post.pageOfPosts
|
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 "/tag/(.*)" Post.pageOfTaggedPosts
|
||||||
GET_HEAD >=> routexp "/themes/(.*)" Asset.serve
|
GET_HEAD >=> routexp "/themes/(.*)" Asset.serve
|
||||||
GET_HEAD >=> routexp "/upload/(.*)" Upload.serve
|
GET_HEAD >=> routexp "/upload/(.*)" Upload.serve
|
||||||
@ -242,7 +259,7 @@ let router : HttpHandler = choose [
|
|||||||
]
|
]
|
||||||
])
|
])
|
||||||
GET_HEAD >=> CatchAll.route
|
GET_HEAD >=> CatchAll.route
|
||||||
Error.notFound
|
//Error.notFound
|
||||||
]
|
]
|
||||||
|
|
||||||
/// Wrap a router in a sub-route
|
/// Wrap a router in a sub-route
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
<Compile Include="DotLiquidBespoke.fs" />
|
<Compile Include="DotLiquidBespoke.fs" />
|
||||||
<Compile Include="Maintenance.fs" />
|
<Compile Include="Maintenance.fs" />
|
||||||
<Compile Include="Program.fs" />
|
<Compile Include="Program.fs" />
|
||||||
|
<Content Include="wwwroot\htmx.min.js" CopyToOutputDirectory="Always" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -7,7 +7,6 @@ open System.IO
|
|||||||
open System.Text
|
open System.Text
|
||||||
open Fluid
|
open Fluid
|
||||||
open Fluid.Values
|
open Fluid.Values
|
||||||
open Giraffe.ViewEngine
|
|
||||||
open Microsoft.AspNetCore.Antiforgery
|
open Microsoft.AspNetCore.Antiforgery
|
||||||
open Microsoft.Extensions.FileProviders
|
open Microsoft.Extensions.FileProviders
|
||||||
open MyWebLog
|
open MyWebLog
|
||||||
@ -237,7 +236,9 @@ let parser =
|
|||||||
fun writer encoder context ->
|
fun writer encoder context ->
|
||||||
let webLog = context.App.WebLog
|
let webLog = context.App.WebLog
|
||||||
if webLog.AutoHtmx then
|
if webLog.AutoHtmx then
|
||||||
writer.WriteLine $"{s}{RenderView.AsString.htmlNode Htmx.Script.minified}"
|
context.App.WebLog.RelativeUrl(Permalink "htmx.min.js")
|
||||||
|
|> sprintf "%s<script src=\"%s\"></script>" s
|
||||||
|
|> writer.WriteLine
|
||||||
if assetExists "script.js" webLog then
|
if assetExists "script.js" webLog then
|
||||||
themeAsset (StringValue "script.js") context
|
themeAsset (StringValue "script.js") context
|
||||||
|> sprintf "%s<script src=\"%s\"></script>" s
|
|> sprintf "%s<script src=\"%s\"></script>" s
|
||||||
|
@ -317,7 +317,7 @@ module Layout =
|
|||||||
script [ _src "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
|
script [ _src "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
|
||||||
_integrity "sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
|
_integrity "sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
|
||||||
_crossorigin "anonymous" ] []
|
_crossorigin "anonymous" ] []
|
||||||
Script.minified
|
script [ _src (relUrl app "htmx.min.js") ] []
|
||||||
script [ _src (relUrl app "themes/admin/admin.js") ] []
|
script [ _src (relUrl app "themes/admin/admin.js") ] []
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
1
src/MyWebLog/wwwroot/htmx.min.js
vendored
Normal file
1
src/MyWebLog/wwwroot/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user