Move OpenGraph property generation to models (#52)
- Add auto-OpenGraph field to web log - Only generate properties for posts/pages without them if this flag is set - Set flag to yes on v3 database migration - Add JSON converter for OpenGraph type - Add tests for models
This commit is contained in:
@@ -192,7 +192,12 @@ let parser =
|
||||
let attrEnc = System.Web.HttpUtility.HtmlAttributeEncode
|
||||
|
||||
// OpenGraph tags
|
||||
if app.IsPage || app.IsPost then
|
||||
let doOpenGraph =
|
||||
(app.WebLog.AutoOpenGraph && (app.IsPage || app.IsPost))
|
||||
|| (app.IsPage && Option.isSome app.Page.OpenGraph)
|
||||
|| (app.IsPost && Option.isSome app.Posts.Posts[0].OpenGraph)
|
||||
|
||||
if doOpenGraph then
|
||||
let writeOgProp (name, value) =
|
||||
writer.WriteLine $"""{s}<meta property=%s{name} content="{attrEnc value}">"""
|
||||
writeOgProp ("og:title", if app.IsPage then app.Page.Title else app.Posts.Posts[0].Title)
|
||||
@@ -202,20 +207,7 @@ let parser =
|
||||
|> app.WebLog.AbsoluteUrl
|
||||
|> function url -> writeOgProp ("og:url", url)
|
||||
match if app.IsPage then app.Page.OpenGraph else app.Posts.Posts[0].OpenGraph with
|
||||
| Some props ->
|
||||
writeOgProp ("og:type", string props.Type)
|
||||
props.Image.Properties |> Seq.iter writeOgProp
|
||||
match props.Description with Some desc -> writeOgProp ("og:description", desc) | None -> ()
|
||||
match props.Determiner with Some det -> writeOgProp ("og:determiner", det) | None -> ()
|
||||
match props.Locale with Some loc -> writeOgProp ("og:locale", loc) | None -> ()
|
||||
match props.LocaleAlternate with
|
||||
| Some alt -> alt |> List.iter (fun it -> writeOgProp ("og:locale:alternate", it))
|
||||
| None -> ()
|
||||
match props.Audio with Some audio -> audio.Properties |> Seq.iter writeOgProp | None -> ()
|
||||
match props.Video with Some video -> video.Properties |> Seq.iter writeOgProp | None -> ()
|
||||
match props.Other with
|
||||
| Some oth -> oth |> List.iter (fun it -> writeOgProp (it.Name, it.Value))
|
||||
| None -> ()
|
||||
| Some props -> props.Properties |> Seq.iter writeOgProp
|
||||
| None -> ()
|
||||
|
||||
writer.WriteLine $"""{s}<meta name=generator content="{app.Generator}">"""
|
||||
|
||||
@@ -795,6 +795,13 @@ let webLogSettings
|
||||
selectField [] (nameof model.Uploads) "Default Upload Destination" model.Uploads uploads
|
||||
string string []
|
||||
]
|
||||
div [ _class "col-12 col-md-6 offset-md-3 col-xl-4 offset-xl-4" ] [
|
||||
checkboxSwitch [] (nameof model.AutoOpenGraph) "Auto-Add OpenGraph Properties"
|
||||
model.AutoOpenGraph []
|
||||
span [ _class "form-text fst-italic" ] [
|
||||
raw "Adds title, site name, and permalink to all pages and posts"
|
||||
]
|
||||
]
|
||||
]
|
||||
div [ _class "row pb-3" ] [
|
||||
div [ _class "col text-center" ] [
|
||||
|
||||
Reference in New Issue
Block a user