diff --git a/src/MyWebLog.Data/Data.fs b/src/MyWebLog.Data/Data.fs index 6139d8a..49389da 100644 --- a/src/MyWebLog.Data/Data.fs +++ b/src/MyWebLog.Data/Data.fs @@ -752,6 +752,7 @@ module WebLog = "postsPerPage", webLog.postsPerPage "timeZone", webLog.timeZone "themePath", webLog.themePath + "autoHtmx", webLog.autoHtmx ] write; withRetryDefault; ignoreResult } diff --git a/src/MyWebLog.Domain/DataTypes.fs b/src/MyWebLog.Domain/DataTypes.fs index a8e8089..8f33973 100644 --- a/src/MyWebLog.Domain/DataTypes.fs +++ b/src/MyWebLog.Domain/DataTypes.fs @@ -275,6 +275,9 @@ type WebLog = /// The RSS options for this web log rss : RssOptions + + /// Whether to automatically load htmx + autoHtmx : bool } /// Functions to support web logs @@ -291,6 +294,7 @@ module WebLog = urlBase = "" timeZone = "" rss = RssOptions.empty + autoHtmx = false } /// Get the host (including scheme) and extra path from the URL base diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs index 7f1327e..a495625 100644 --- a/src/MyWebLog.Domain/ViewModels.fs +++ b/src/MyWebLog.Domain/ViewModels.fs @@ -676,7 +676,11 @@ type SettingsModel = /// The theme to use to display the web log themePath : string + + /// Whether to automatically load htmx + autoHtmx : bool } + /// Create a settings model from a web log static member fromWebLog (webLog : WebLog) = { name = webLog.name @@ -685,6 +689,19 @@ type SettingsModel = postsPerPage = webLog.postsPerPage timeZone = webLog.timeZone themePath = webLog.themePath + autoHtmx = webLog.autoHtmx + } + + /// Update a web log with settings from the form + member this.update (webLog : WebLog) = + { webLog with + name = this.name + subtitle = if this.subtitle = "" then None else Some this.subtitle + defaultPage = this.defaultPage + postsPerPage = this.postsPerPage + timeZone = this.timeZone + themePath = this.themePath + autoHtmx = this.autoHtmx } diff --git a/src/MyWebLog/DotLiquidBespoke.fs b/src/MyWebLog/DotLiquidBespoke.fs index 122ca0f..95c1578 100644 --- a/src/MyWebLog/DotLiquidBespoke.fs +++ b/src/MyWebLog/DotLiquidBespoke.fs @@ -5,12 +5,17 @@ open System open System.IO open System.Web open DotLiquid +open Giraffe.ViewEngine open MyWebLog.ViewModels /// Get the current web log from the DotLiquid context let webLog (ctx : Context) = ctx.Environments[0].["web_log"] :?> WebLog +/// Does an asset exist for the current theme? +let assetExists fileName (webLog : WebLog) = + File.Exists (Path.Combine ("wwwroot", "themes", webLog.themePath, fileName)) + /// Obtain the link from known types let permalink (ctx : Context) (item : obj) (linkFunc : WebLog -> Permalink -> string) = match item with @@ -72,9 +77,11 @@ type EditPostLinkFilter () = type NavLinkFilter () = static member NavLink (ctx : Context, url : string, text : string) = let webLog = webLog ctx + let _, path = WebLog.hostAndPath webLog + let path = if path = "" then path else $"{path.Substring 1}/" seq { "
  • " @@ -98,10 +105,9 @@ type PageHeadTag () = result.WriteLine $"""""" // Theme assets - let has fileName = File.Exists (Path.Combine ("wwwroot", "themes", webLog.themePath, fileName)) - if has "style.css" then + if assetExists "style.css" webLog then result.WriteLine $"""{s}""" - if has "favicon.ico" then + if assetExists "favicon.ico" webLog then result.WriteLine $"""{s}""" // RSS feeds and canonical URLs @@ -132,6 +138,22 @@ type PageHeadTag () = let url = WebLog.absoluteUrl webLog (Permalink page.permalink) result.WriteLine $"""{s}""" + +/// Create various items in the page header based on the state of the page being generated +type PageFootTag () = + inherit Tag () + + override this.Render (context : Context, result : TextWriter) = + let webLog = webLog context + // spacer + let s = " " + + if webLog.autoHtmx then + result.WriteLine $"{s}{RenderView.AsString.htmlNode Htmx.Script.minified}" + + if assetExists "script.js" webLog then + result.WriteLine $"""{s}""" + /// A filter to generate a relative link type RelativeLinkFilter () = @@ -167,7 +189,7 @@ type UserLinksTag () = """