WIP on pulling embedded htmx
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
/// Routes for this application
|
/// Routes for this application
|
||||||
module MyWebLog.Handlers.Routes
|
module MyWebLog.Handlers.Routes
|
||||||
|
|
||||||
|
open System.Reflection
|
||||||
open Giraffe
|
open Giraffe
|
||||||
open Microsoft.AspNetCore.Http
|
open Microsoft.AspNetCore.Http
|
||||||
|
open Microsoft.Extensions.FileProviders
|
||||||
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)
|
||||||
@@ -11,6 +13,9 @@ module CatchAll =
|
|||||||
open System.IO
|
open System.IO
|
||||||
open MyWebLog.ViewModels
|
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
|
/// 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,6 +27,7 @@ module CatchAll =
|
|||||||
(if extra = "" then url else url[extra.Length..]).ToLowerInvariant()
|
(if extra = "" then url else url[extra.Length..]).ToLowerInvariant()
|
||||||
let await it = (Async.AwaitTask >> Async.RunSynchronously) it
|
let await it = (Async.AwaitTask >> Async.RunSynchronously) it
|
||||||
seq {
|
seq {
|
||||||
|
// Static file
|
||||||
debug (fun () -> $"Considering URL {textLink}")
|
debug (fun () -> $"Considering URL {textLink}")
|
||||||
let staticFileName =
|
let staticFileName =
|
||||||
[ ctx.GetWebHostEnvironment().ContentRootPath
|
[ ctx.GetWebHostEnvironment().ContentRootPath
|
||||||
@@ -35,6 +41,32 @@ module CatchAll =
|
|||||||
|> System.DateTimeOffset
|
|> System.DateTimeOffset
|
||||||
|> Some
|
|> Some
|
||||||
|> streamFile true staticFileName None
|
|> 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
|
// 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..]
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
open Microsoft.AspNetCore.Http
|
open Microsoft.AspNetCore.Hosting
|
||||||
|
open Microsoft.AspNetCore.Http
|
||||||
open Microsoft.Data.Sqlite
|
open Microsoft.Data.Sqlite
|
||||||
open Microsoft.Extensions.Configuration
|
open Microsoft.Extensions.Configuration
|
||||||
open Microsoft.Extensions.Logging
|
open Microsoft.Extensions.Logging
|
||||||
@@ -141,7 +142,7 @@ open RethinkDB.DistributedCache
|
|||||||
[<EntryPoint>]
|
[<EntryPoint>]
|
||||||
let main args =
|
let main args =
|
||||||
|
|
||||||
let builder = WebApplication.CreateBuilder(args)
|
let builder = WebApplication.CreateBuilder args
|
||||||
let _ = builder.Services.Configure<ForwardedHeadersOptions>(fun (opts : ForwardedHeadersOptions) ->
|
let _ = builder.Services.Configure<ForwardedHeadersOptions>(fun (opts : ForwardedHeadersOptions) ->
|
||||||
opts.ForwardedHeaders <- ForwardedHeaders.XForwardedFor ||| ForwardedHeaders.XForwardedProto)
|
opts.ForwardedHeaders <- ForwardedHeaders.XForwardedFor ||| ForwardedHeaders.XForwardedProto)
|
||||||
let _ =
|
let _ =
|
||||||
@@ -198,6 +199,7 @@ let main args =
|
|||||||
opts.IdleTimeout <- TimeSpan.FromMinutes 60.
|
opts.IdleTimeout <- TimeSpan.FromMinutes 60.
|
||||||
opts.Cookie.HttpOnly <- true
|
opts.Cookie.HttpOnly <- true
|
||||||
opts.Cookie.IsEssential <- true)
|
opts.Cookie.IsEssential <- true)
|
||||||
|
let _ = builder.WebHost.UseStaticWebAssets()
|
||||||
let _ = builder.Services.AddGiraffe()
|
let _ = builder.Services.AddGiraffe()
|
||||||
|
|
||||||
// Set up DotLiquid
|
// 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"
|
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 [ _src (relUrl app "htmx.min.js") ] []
|
//script [ _src (relUrl app "htmx.min.js") ] []
|
||||||
|
Script.local
|
||||||
script [ _src (relUrl app "themes/admin/admin.js") ] []
|
script [ _src (relUrl app "themes/admin/admin.js") ] []
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user