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
|
||||||
@ -188,7 +189,7 @@ let viewForTheme themeId template next ctx (viewCtx: AppViewContext) = task {
|
|||||||
let forLayout = { updated with Content = Template.render contentTemplate updated ctx.Data }
|
let forLayout = { updated with Content = Template.render contentTemplate updated ctx.Data }
|
||||||
// ...then render that content with its layout
|
// ...then render that content with its layout
|
||||||
match! Template.Cache.get themeId (if isHtmx ctx then "layout-partial" else "layout") ctx.Data with
|
match! Template.Cache.get themeId (if isHtmx ctx then "layout-partial" else "layout") ctx.Data with
|
||||||
| Ok layoutTemplate -> return! htmlString (Template.render layoutTemplate forLayout ctx.Data) next ctx
|
| Ok layoutTemplate -> return! htmlString (Template.render layoutTemplate forLayout ctx.Data) next ctx
|
||||||
| Error message -> return! Error.server message next ctx
|
| Error message -> return! Error.server message next ctx
|
||||||
| Error message -> return! Error.server message next ctx
|
| Error message -> return! Error.server message next ctx
|
||||||
}
|
}
|
||||||
|
@ -164,9 +164,12 @@ 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
|
||||||
|> Seq.tryPick picker
|
| :? NilValue -> $"-- {name} not found --"
|
||||||
|> Option.defaultValue $"-- {name} not found --"
|
| it ->
|
||||||
|
(it :?> ArrayValue).Values
|
||||||
|
|> Seq.tryPick picker
|
||||||
|
|> Option.defaultValue $"-- {name} not found --"
|
||||||
|> sValue)
|
|> sValue)
|
||||||
|
|
||||||
it
|
it
|
||||||
@ -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 ())
|
||||||
|
@ -97,6 +97,10 @@ type AppViewContext = {
|
|||||||
/// <summary>The payload for this page as a <c>PostDisplay</c></summary>
|
/// <summary>The payload for this page as a <c>PostDisplay</c></summary>
|
||||||
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 =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user