Add OG types to page/post, add rendering in page head (#52)
This commit is contained in:
@@ -188,9 +188,35 @@ let parser =
|
||||
// Create various items in the page header based on the state of the page being generated
|
||||
it.RegisterEmptyTag("page_head",
|
||||
fun writer encoder context ->
|
||||
let app = context.App
|
||||
// let getBool name =
|
||||
// defaultArg (context.Environments[0].[name] |> Option.ofObj |> Option.map Convert.ToBoolean) false
|
||||
let app = context.App
|
||||
let attrEnc = System.Web.HttpUtility.HtmlAttributeEncode
|
||||
|
||||
// OpenGraph tags
|
||||
if app.IsPage || app.IsPost 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)
|
||||
writeOgProp ("og:site_name", app.WebLog.Name)
|
||||
if app.IsPage then app.Page.Permalink else app.Posts.Posts[0].Permalink
|
||||
|> Permalink
|
||||
|> 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 -> ()
|
||||
| None -> ()
|
||||
|
||||
writer.WriteLine $"""{s}<meta name=generator content="{app.Generator}">"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user