Support relative URLs in OpenGraph properties (#52)

This commit is contained in:
2025-08-01 22:16:19 -04:00
parent 8b190a6c23
commit cba1bbfa28
9 changed files with 172 additions and 140 deletions
+8 -13
View File
@@ -504,21 +504,18 @@ type EditCommonModel() =
post.OpenGraph |> Option.iter this.PopulateOpenGraph
/// <summary>Convert the properties of the model into a set of OpenGraph properties</summary>
/// <param name="webLog">The current web log</param>
member this.ToOpenGraph(webLog: WebLog) =
member this.ToOpenGraph() =
if this.AssignOpenGraph then
let toAbsolute (url: string) =
if url.StartsWith "http" then url else webLog.AbsoluteUrl (Permalink url)
let audio =
match this.OpenGraphAudioUrl.Trim() with
| "" -> None
| url -> Some { OpenGraphAudio.Url = toAbsolute url; Type = noneIfBlank this.OpenGraphAudioType }
| url -> Some { OpenGraphAudio.Url = url; Type = noneIfBlank this.OpenGraphAudioType }
let video =
match this.OpenGraphVideoUrl.Trim() with
| "" -> None
| url ->
Some {
OpenGraphVideo.Url = toAbsolute url
OpenGraphVideo.Url = url
Type = noneIfBlank this.OpenGraphVideoType
Width = noneIfBlank this.OpenGraphVideoWidth |> Option.map int
Height = noneIfBlank this.OpenGraphVideoHeight |> Option.map int
@@ -526,7 +523,7 @@ type EditCommonModel() =
Some {
Type = if this.OpenGraphType = "" then Article else OpenGraphType.Parse this.OpenGraphType
Image = {
Url = toAbsolute this.OpenGraphImageUrl
Url = this.OpenGraphImageUrl
Type = noneIfBlank this.OpenGraphImageType
Width = noneIfBlank this.OpenGraphImageWidth |> Option.map int
Height = noneIfBlank this.OpenGraphImageHeight |> Option.map int
@@ -749,10 +746,9 @@ type EditPageModel() =
/// <summary>Update a page with values from this model</summary>
/// <param name="page">The page to be updated</param>
/// <param name="webLog">The web log to which this page belongs</param>
/// <param name="now">The <c>Instant</c> to use for this particular update</param>
/// <returns>The page, updated with the values from this model</returns>
member this.UpdatePage (page: Page) webLog now =
member this.UpdatePage (page: Page) now =
let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" }
// Detect a permalink change, and add the prior one to the prior list
match string page.Permalink with
@@ -768,7 +764,7 @@ type EditPageModel() =
IsInPageList = this.IsShownInPageList
Template = match this.Template with "" -> None | tmpl -> Some tmpl
Text = revision.Text.AsHtml()
OpenGraph = this.ToOpenGraph webLog
OpenGraph = this.ToOpenGraph()
Metadata = Seq.zip this.MetaNames this.MetaValues
|> Seq.filter (fun it -> fst it > "")
|> Seq.map (fun it -> { Name = fst it; Value = snd it })
@@ -908,10 +904,9 @@ type EditPostModel() =
/// <summary>Update a post with values from the submitted form</summary>
/// <param name="post">The post which should be updated</param>
/// <param name="webLog">The web log to which this post belongs</param>
/// <param name="now">The <c>Instant</c> to use for this particular update</param>
/// <returns>The post, updated with the values from this model</returns>
member this.UpdatePost (post: Post) (webLog: WebLog) now =
member this.UpdatePost (post: Post) now =
let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" }
// Detect a permalink change, and add the prior one to the prior list
match string post.Permalink with
@@ -935,7 +930,7 @@ type EditPostModel() =
Template = match this.Template.Trim() with "" -> None | tmpl -> Some tmpl
CategoryIds = this.CategoryIds |> Array.map CategoryId |> List.ofArray
Status = if this.DoPublish then Published else post.Status
OpenGraph = this.ToOpenGraph webLog
OpenGraph = this.ToOpenGraph()
Metadata = Seq.zip this.MetaNames this.MetaValues
|> Seq.filter (fun it -> fst it > "")
|> Seq.map (fun it -> { Name = fst it; Value = snd it })