Add model alias for payload (#47)
- Update post/page canonical URLs for Fluid
This commit is contained in:
parent
ba5e27e011
commit
1f7d415868
@ -69,7 +69,8 @@ open Giraffe.Htmx
|
|||||||
open Giraffe.ViewEngine
|
open Giraffe.ViewEngine
|
||||||
|
|
||||||
/// htmx script tag
|
/// htmx script tag
|
||||||
let private htmxScript = RenderView.AsString.htmlNode Htmx.Script.minified
|
let private htmxScript (webLog: WebLog) =
|
||||||
|
$"""<script src="{webLog.RelativeUrl(Permalink "htmx.min.js")}"></script>"""
|
||||||
|
|
||||||
/// Get the current user messages, and commit the session so that they are preserved
|
/// Get the current user messages, and commit the session so that they are preserved
|
||||||
let private getCurrentMessages ctx = task {
|
let private getCurrentMessages ctx = task {
|
||||||
@ -91,7 +92,7 @@ let private generateViewContext messages viewCtx (ctx: HttpContext) =
|
|||||||
CurrentPage = ctx.Request.Path.Value[1..]
|
CurrentPage = ctx.Request.Path.Value[1..]
|
||||||
Messages = messages
|
Messages = messages
|
||||||
Generator = ctx.Generator
|
Generator = ctx.Generator
|
||||||
HtmxScript = htmxScript
|
HtmxScript = htmxScript ctx.WebLog
|
||||||
IsAuthor = ctx.HasAccessLevel Author
|
IsAuthor = ctx.HasAccessLevel Author
|
||||||
IsEditor = ctx.HasAccessLevel Editor
|
IsEditor = ctx.HasAccessLevel Editor
|
||||||
IsWebLogAdmin = ctx.HasAccessLevel WebLogAdmin
|
IsWebLogAdmin = ctx.HasAccessLevel WebLogAdmin
|
||||||
|
@ -164,7 +164,10 @@ let options () =
|
|||||||
let picker (value: FluidValue) =
|
let picker (value: FluidValue) =
|
||||||
let item = value.ToObjectValue() :?> MetaItem
|
let item = value.ToObjectValue() :?> MetaItem
|
||||||
if item.Name = name then Some item.Value else None
|
if item.Name = name then Some item.Value else None
|
||||||
(input :?> ArrayValue).Values
|
match input with
|
||||||
|
| :? NilValue -> $"-- {name} not found --"
|
||||||
|
| it ->
|
||||||
|
(it :?> ArrayValue).Values
|
||||||
|> Seq.tryPick picker
|
|> Seq.tryPick picker
|
||||||
|> Option.defaultValue $"-- {name} not found --"
|
|> Option.defaultValue $"-- {name} not found --"
|
||||||
|> sValue)
|
|> sValue)
|
||||||
@ -220,13 +223,11 @@ let parser =
|
|||||||
writer.WriteLine(feedLink app.WebLog.Name $"tag/{slug}/{app.WebLog.Rss.FeedName}")
|
writer.WriteLine(feedLink app.WebLog.Name $"tag/{slug}/{app.WebLog.Rss.FeedName}")
|
||||||
|
|
||||||
if app.IsPost then
|
if app.IsPost then
|
||||||
let post = (* context.Environments[0].["model"] *) obj() :?> PostDisplay
|
let url = app.WebLog.AbsoluteUrl(Permalink app.Posts.Posts[0].Permalink)
|
||||||
let url = app.WebLog.AbsoluteUrl(Permalink post.Posts[0].Permalink)
|
|
||||||
writer.WriteLine $"""{s}<link rel=canonical href="{url}">"""
|
writer.WriteLine $"""{s}<link rel=canonical href="{url}">"""
|
||||||
|
|
||||||
if app.IsPage then
|
if app.IsPage then
|
||||||
let page = (* context.Environments[0].["page"] *) obj() :?> DisplayPage
|
let url = app.WebLog.AbsoluteUrl(Permalink app.Page.Permalink)
|
||||||
let url = app.WebLog.AbsoluteUrl(Permalink page.Permalink)
|
|
||||||
writer.WriteLine $"""{s}<link rel=canonical href="{url}">"""
|
writer.WriteLine $"""{s}<link rel=canonical href="{url}">"""
|
||||||
|
|
||||||
ok ())
|
ok ())
|
||||||
|
@ -98,6 +98,10 @@ type AppViewContext = {
|
|||||||
member this.Posts =
|
member this.Posts =
|
||||||
this.Payload :?> PostDisplay
|
this.Payload :?> PostDisplay
|
||||||
|
|
||||||
|
/// <summary>The model for this view (prior versions used <c>model</c> for the v3 <c>payload</c>)</summary>
|
||||||
|
member this.Model =
|
||||||
|
this.Payload
|
||||||
|
|
||||||
/// <summary>An empty view context</summary>
|
/// <summary>An empty view context</summary>
|
||||||
static member Empty =
|
static member Empty =
|
||||||
{ WebLog = WebLog.Empty
|
{ WebLog = WebLog.Empty
|
||||||
|
Loading…
x
Reference in New Issue
Block a user