Add Fluid where filter, fix slug (#47)

- Fix issue with path base and logon redirects
This commit is contained in:
2026-07-07 22:57:57 -04:00
parent 8e0b2df870
commit b3eab09576
5 changed files with 40 additions and 19 deletions
+7 -1
View File
@@ -139,7 +139,13 @@ module Error =
/// Handle unauthorized actions, redirecting to log on for GETs, otherwise returning a 401 Not Authorized response
let notAuthorized : HttpHandler = fun next ctx ->
if ctx.Request.Method = "GET" then
let redirectUrl = $"user/log-on?returnUrl={WebUtility.UrlEncode ctx.Request.Path}"
let fullPath =
String.concat ""
(seq {
if ctx.Request.PathBase.HasValue then yield ctx.Request.PathBase.Value
yield ctx.Request.Path.Value
})
let redirectUrl = $"user/log-on?returnUrl={WebUtility.UrlEncode fullPath}"
(next, ctx)
||> if isHtmx ctx then withHxRedirect redirectUrl >=> withHxRetarget "body" >=> redirectToGet redirectUrl
else redirectToGet redirectUrl
+18 -3
View File
@@ -172,6 +172,21 @@ let options () =
|> Option.defaultValue $"-- {name} not found --"
|> sValue)
// A filter to search through a collection of objects for a matching property
it.Filters.AddFilter("where",
fun input args ctx ->
let name = args.At(0).ToStringValue()
let value = args.At(1).ToStringValue()
input.Enumerate(ctx)
|> Seq.filter (fun it ->
let theItem = it.ToObjectValue()
match theItem.GetType().GetProperties() |> Array.tryFind (fun x -> x.Name = name) with
| Some pi -> pi.GetValue(theItem) = value
| None -> false)
|> Seq.toArray
|> ArrayValue :> FluidValue
|> VTask)
it
open Giraffe.Htmx.Common
@@ -234,11 +249,11 @@ let parser =
writer.WriteLine $"""{s}<link rel=canonical href="{app.WebLog.AbsoluteUrl Permalink.Empty}">"""
if app.WebLog.Rss.IsCategoryEnabled && app.IsCategoryHome then
let slug = context.AmbientValues["slug"] :?> string
let slug = (context.Model.ToObjectValue() :?> AppViewContext).Slug
writer.WriteLine(feedLink app.WebLog.Name $"category/{slug}/{app.WebLog.Rss.FeedName}")
if app.WebLog.Rss.IsTagEnabled && app.IsTagHome then
let slug = context.AmbientValues["slug"] :?> string
let slug = (context.Model.ToObjectValue() :?> AppViewContext).Slug
writer.WriteLine(feedLink app.WebLog.Name $"tag/{slug}/{app.WebLog.Rss.FeedName}")
if app.IsPost then
@@ -287,7 +302,7 @@ let parser =
"</ul>"
}
|> Seq.iter writer.WriteLine
ok())
ok ())
it
+2 -2
View File
@@ -13,8 +13,8 @@
</a>
</h1>
<p>
Published on {{ post.published_on | date: "MMMM d, yyyy" }}
at {{ post.published_on | date: "h:mmtt" | downcase }}
Published on {{ post.published_on | format_date: "MMMM d, yyyy" }}
at {{ post.published_on | format_date: "h:mmtt" | downcase }}
by {{ model.authors | value: post.author_id }}
{{ post.text }}
{%- assign category_count = post.category_ids | size -%}
+2 -2
View File
@@ -2,8 +2,8 @@
<h1>{{ post.title }}</h1>
<h4 class="item-meta text-muted">
{% if post.published_on -%}
Published {{ post.published_on | date: "dddd, MMMM d, yyyy" }}
at {{ post.published_on | date: "h:mm tt" | downcase }}
Published {{ post.published_on | format_date: "dddd, MMMM d, yyyy" }}
at {{ post.published_on | format_date: "h:mm tt" | downcase }}
{%- else -%}
**DRAFT**
{% endif %}
+1 -1
View File
@@ -1,2 +1,2 @@
myWebLog Default Theme
2.2
3