WIP on OpenGraph post/page model (#52)
- Removed SecureUrl prop; will generate if URL starts with https:
This commit is contained in:
@@ -372,6 +372,63 @@ type EditCommonModel() =
|
||||
/// <summary>The text of the page or post</summary>
|
||||
member val Text = "" with get, set
|
||||
|
||||
/// <summary>Whether to assign OpenGraph properties to this page or post</summary>
|
||||
member val AssignOpenGraph = false with get, set
|
||||
|
||||
/// <summary>The type of object represented by this page or post</summary>
|
||||
member val OpenGraphType = "" with get, set
|
||||
|
||||
/// <summary>The URL for the image associated with this page or post</summary>
|
||||
member val OpenGraphImageUrl = "" with get, set
|
||||
|
||||
/// <summary>The MIME type of the image associated with this page or post</summary>
|
||||
member val OpenGraphImageType = "" with get, set
|
||||
|
||||
/// <summary>The width of the image associated with this page or post</summary>
|
||||
member val OpenGraphImageWidth = "" with get, set
|
||||
|
||||
/// <summary>The height of the image associated with this page or post</summary>
|
||||
member val OpenGraphImageHeight = "" with get, set
|
||||
|
||||
/// <summary>The alternate text for the image associated with this page or post</summary>
|
||||
member val OpenGraphImageAlt = "" with get, set
|
||||
|
||||
/// <summary>The URL of an audio file associated with this page or post</summary>
|
||||
member val OpenGraphAudioUrl = "" with get, set
|
||||
|
||||
/// <summary>The MIME type of the audio file associated with this page or post</summary>
|
||||
member val OpenGraphAudioType = "" with get, set
|
||||
|
||||
/// <summary>A short description of this page or post</summary>
|
||||
member val OpenGraphDescription = "" with get, set
|
||||
|
||||
/// <summary>A word excluded from the title when alphabetizing</summary>
|
||||
member val OpenGraphDeterminer = "" with get, set
|
||||
|
||||
/// <summary>The primary locale for this page or post</summary>
|
||||
member val OpenGraphLocale = "" with get, set
|
||||
|
||||
/// <summary>Alternate locales in which this page or post is available</summary>
|
||||
member val OpenGraphAlternateLocales = "" with get, set
|
||||
|
||||
/// <summary>The URL of a video file associated with this page or post</summary>
|
||||
member val OpenGraphVideoUrl = "" with get, set
|
||||
|
||||
/// <summary>The MIME type of a video file associated with this page or post</summary>
|
||||
member val OpenGraphVideoType = "" with get, set
|
||||
|
||||
/// <summary>The width of the video file associated with this page or post</summary>
|
||||
member val OpenGraphVideoWidth = "" with get, set
|
||||
|
||||
/// <summary>The height of the video file associated with this page or post</summary>
|
||||
member val OpenGraphVideoHeight = "" with get, set
|
||||
|
||||
/// <summary>The names of extra OpenGraph properties for this page or post</summary>
|
||||
member val OpenGraphExtraNames: string array = [||] with get, set
|
||||
|
||||
/// <summary>The values of extra OpenGraph properties for this page or post</summary>
|
||||
member val OpenGraphExtraValues: string array = [||] with get, set
|
||||
|
||||
/// <summary>Names of metadata items</summary>
|
||||
member val MetaNames: string array = [||] with get, set
|
||||
|
||||
@@ -381,9 +438,40 @@ type EditCommonModel() =
|
||||
/// <summary>Whether this is a new page or post</summary>
|
||||
member this.IsNew with get () = this.Id = "new"
|
||||
|
||||
/// <summary>Populate the OpenGraph properties</summary>
|
||||
/// <param name="og">The existing OpenGraph property set</param>
|
||||
member private this.PopulateOpenGraph(og: OpenGraphProperties) =
|
||||
this.AssignOpenGraph <- true
|
||||
this.OpenGraphImageUrl <- og.Image.Url
|
||||
this.OpenGraphImageType <- defaultArg og.Image.Type ""
|
||||
this.OpenGraphImageWidth <- defaultArg (og.Image.Width |> Option.map string) ""
|
||||
this.OpenGraphImageHeight <- defaultArg (og.Image.Height |> Option.map string) ""
|
||||
this.OpenGraphImageAlt <- defaultArg og.Image.Alt ""
|
||||
this.OpenGraphDescription <- defaultArg og.Description ""
|
||||
this.OpenGraphDeterminer <- defaultArg og.Determiner ""
|
||||
this.OpenGraphLocale <- defaultArg og.Locale ""
|
||||
this.OpenGraphAlternateLocales <- defaultArg (og.LocaleAlternate |> Option.map (String.concat ", ")) ""
|
||||
match og.Audio with
|
||||
| Some audio ->
|
||||
this.OpenGraphAudioUrl <- audio.Url
|
||||
this.OpenGraphAudioType <- defaultArg audio.Type ""
|
||||
| None -> ()
|
||||
match og.Video with
|
||||
| Some video ->
|
||||
this.OpenGraphVideoUrl <- video.Url
|
||||
this.OpenGraphVideoType <- defaultArg video.Type ""
|
||||
this.OpenGraphVideoWidth <- defaultArg (video.Width |> Option.map string) ""
|
||||
this.OpenGraphVideoHeight <- defaultArg (video.Height |> Option.map string) ""
|
||||
| None -> ()
|
||||
match og.Other with
|
||||
| Some other ->
|
||||
this.OpenGraphExtraNames <- other |> List.map _.Name |> Array.ofList
|
||||
this.OpenGraphExtraValues <- other |> List.map _.Value |> Array.ofList
|
||||
| None -> ()
|
||||
|
||||
/// <summary>Fill the properties of this object from a page</summary>
|
||||
/// <param name="page">The page from which this model should be populated</param>
|
||||
member this.PopulateFromPage (page: Page) =
|
||||
member this.PopulateFromPage(page: Page) =
|
||||
let latest = findLatestRevision page.Revisions
|
||||
let metaItems = if page.Metadata.Length = 0 then [ MetaItem.Empty ] else page.Metadata
|
||||
this.Id <- string page.Id
|
||||
@@ -395,10 +483,11 @@ type EditCommonModel() =
|
||||
this.Text <- latest.Text.Text
|
||||
this.MetaNames <- metaItems |> List.map _.Name |> Array.ofList
|
||||
this.MetaValues <- metaItems |> List.map _.Value |> Array.ofList
|
||||
page.OpenGraph |> Option.iter this.PopulateOpenGraph
|
||||
|
||||
/// <summary>Fill the properties of this object from a post</summary>
|
||||
/// <param name="post">The post from which this model should be populated</param>
|
||||
member this.PopulateFromPost (post: Post) =
|
||||
member this.PopulateFromPost(post: Post) =
|
||||
let latest = findLatestRevision post.Revisions
|
||||
let metaItems = if post.Metadata.Length = 0 then [ MetaItem.Empty ] else post.Metadata
|
||||
this.Id <- string post.Id
|
||||
@@ -411,7 +500,52 @@ type EditCommonModel() =
|
||||
this.Text <- latest.Text.Text
|
||||
this.MetaNames <- metaItems |> List.map _.Name |> Array.ofList
|
||||
this.MetaValues <- metaItems |> List.map _.Value |> Array.ofList
|
||||
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) =
|
||||
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 }
|
||||
let video =
|
||||
match this.OpenGraphVideoUrl.Trim() with
|
||||
| "" -> None
|
||||
| url ->
|
||||
Some {
|
||||
OpenGraphVideo.Url = toAbsolute url
|
||||
Type = noneIfBlank this.OpenGraphVideoType
|
||||
Width = noneIfBlank this.OpenGraphVideoWidth |> Option.map int
|
||||
Height = noneIfBlank this.OpenGraphVideoHeight |> Option.map int
|
||||
}
|
||||
Some {
|
||||
Type = if this.OpenGraphType = "" then Article else OpenGraphType.Parse this.OpenGraphType
|
||||
Image = {
|
||||
Url = toAbsolute this.OpenGraphImageUrl
|
||||
Type = noneIfBlank this.OpenGraphImageType
|
||||
Width = noneIfBlank this.OpenGraphImageWidth |> Option.map int
|
||||
Height = noneIfBlank this.OpenGraphImageHeight |> Option.map int
|
||||
Alt = noneIfBlank this.OpenGraphImageAlt
|
||||
}
|
||||
Description = noneIfBlank this.OpenGraphDescription
|
||||
Determiner = noneIfBlank this.OpenGraphDeterminer
|
||||
Locale = noneIfBlank this.OpenGraphLocale
|
||||
LocaleAlternate = noneIfBlank this.OpenGraphAlternateLocales
|
||||
|> Option.map (fun alts -> alts.Split ',' |> Array.map _.Trim() |> List.ofArray)
|
||||
Audio = audio
|
||||
Video = video
|
||||
Other = Seq.zip this.OpenGraphExtraNames this.OpenGraphExtraValues
|
||||
|> Seq.filter (fun it -> fst it > "")
|
||||
|> Seq.map (fun it -> { Name = fst it; Value = snd it })
|
||||
|> List.ofSeq
|
||||
|> function it -> match it with [] -> None | _ -> Some it
|
||||
}
|
||||
else
|
||||
None
|
||||
|
||||
/// <summary>View model to edit a custom RSS feed</summary>
|
||||
[<CLIMutable; NoComparison; NoEquality>]
|
||||
|
||||
Reference in New Issue
Block a user