WIP on pulling embedded htmx
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
/// Routes for this application
|
||||
module MyWebLog.Handlers.Routes
|
||||
|
||||
open System.Reflection
|
||||
open Giraffe
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.Extensions.FileProviders
|
||||
open MyWebLog
|
||||
|
||||
/// Module to resolve routes that do not match any other known route (web blog content)
|
||||
@@ -11,6 +13,9 @@ module CatchAll =
|
||||
open System.IO
|
||||
open MyWebLog.ViewModels
|
||||
|
||||
/// URLs for the embedded htmx scripts
|
||||
let htmxUrls = [ "giraffe.htmx.common/htmx.min.js"; "giraffe.htmx.common/htmax.min.js" ]
|
||||
|
||||
/// 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,6 +27,7 @@ module CatchAll =
|
||||
(if extra = "" then url else url[extra.Length..]).ToLowerInvariant()
|
||||
let await it = (Async.AwaitTask >> Async.RunSynchronously) it
|
||||
seq {
|
||||
// Static file
|
||||
debug (fun () -> $"Considering URL {textLink}")
|
||||
let staticFileName =
|
||||
[ ctx.GetWebHostEnvironment().ContentRootPath
|
||||
@@ -35,6 +41,32 @@ module CatchAll =
|
||||
|> System.DateTimeOffset
|
||||
|> Some
|
||||
|> streamFile true staticFileName None
|
||||
// Embedded htmx library
|
||||
if htmxUrls |> List.exists textLink.EndsWith then
|
||||
debug (fun () -> "Embedded htmx script")
|
||||
let asm = Assembly.Load "Giraffe.Htmx.Common"
|
||||
asm.GetManifestResourceNames() |> Array.iter (fun it -> debug (fun () -> $"Resource {it}"))
|
||||
let name = textLink.Split("/") |> Array.last |> sprintf "Giraffe.Htmx.Common/%s"
|
||||
use fs = asm.GetManifestResourceStream name
|
||||
if isNull fs then
|
||||
debug (fun () -> $"No stream found for {name}")
|
||||
else
|
||||
debug (fun () -> $"Found {name}")
|
||||
yield streamData true fs None None
|
||||
// let files = EmbeddedFileProvider(Assembly.Load "Giraffe.Htmx.Common")
|
||||
// let cont = files.GetDirectoryContents "."
|
||||
// if cont.Exists then
|
||||
// debug (fun () -> "Contents found in file provider, here comes the list")
|
||||
// debug (fun () -> $"%A{cont}")
|
||||
// cont |> Seq.iter (fun it -> debug (fun () -> "Path = " + it.PhysicalPath))
|
||||
// else
|
||||
// debug (fun () -> "No contents found in file provider")
|
||||
// let file = files.GetFileInfo (textLink.Replace("giraffe.htmx.common", "Giraffe.Htmx.Common"))
|
||||
// debug (fun () -> $"File info created; {textLink} exists = {file.Exists}")
|
||||
// if file.Exists then
|
||||
// use contents = file.CreateReadStream()
|
||||
// yield streamData true contents None None
|
||||
//yield None
|
||||
// Home page directory without the directory slash
|
||||
if textLink = "" then yield redirectTo true (webLog.RelativeUrl Permalink.Empty)
|
||||
let permalink = Permalink textLink[1..]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.AspNetCore.Hosting
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.Data.Sqlite
|
||||
open Microsoft.Extensions.Configuration
|
||||
open Microsoft.Extensions.Logging
|
||||
@@ -141,7 +142,7 @@ open RethinkDB.DistributedCache
|
||||
[<EntryPoint>]
|
||||
let main args =
|
||||
|
||||
let builder = WebApplication.CreateBuilder(args)
|
||||
let builder = WebApplication.CreateBuilder args
|
||||
let _ = builder.Services.Configure<ForwardedHeadersOptions>(fun (opts : ForwardedHeadersOptions) ->
|
||||
opts.ForwardedHeaders <- ForwardedHeaders.XForwardedFor ||| ForwardedHeaders.XForwardedProto)
|
||||
let _ =
|
||||
@@ -198,6 +199,7 @@ let main args =
|
||||
opts.IdleTimeout <- TimeSpan.FromMinutes 60.
|
||||
opts.Cookie.HttpOnly <- true
|
||||
opts.Cookie.IsEssential <- true)
|
||||
let _ = builder.WebHost.UseStaticWebAssets()
|
||||
let _ = builder.Services.AddGiraffe()
|
||||
|
||||
// Set up DotLiquid
|
||||
|
||||
@@ -317,7 +317,8 @@ module Layout =
|
||||
script [ _src "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
|
||||
_integrity "sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
|
||||
_crossorigin "anonymous" ] []
|
||||
script [ _src (relUrl app "htmx.min.js") ] []
|
||||
//script [ _src (relUrl app "htmx.min.js") ] []
|
||||
Script.local
|
||||
script [ _src (relUrl app "themes/admin/admin.js") ] []
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user