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..]
|
||||
|
||||
Reference in New Issue
Block a user