WIP on OpenGraph types (#52)

This commit is contained in:
Daniel J. Summers 2025-07-06 22:09:36 -04:00
parent c19f92889e
commit fa4e1d327a

View File

@ -382,6 +382,171 @@ type Revision = {
{ AsOf = Noda.epoch; Text = Html "" } { AsOf = Noda.epoch; Text = Html "" }
/// <summary>Properties for an OpenGraph audio file</summary>
[<CLIMutable>]
type OpenGraphAudio = {
/// <summary>The URL for this audio file</summary>
Url: string
/// <summary>The URL for this audio file for sites that require https</summary>
SecureUrl: string option
/// <summary>The MIME type of the audio file</summary>
Type: string option
} with
/// <summary>An empty audio file</summary>
static member Empty =
{ Url = ""
SecureUrl = None
Type = None }
/// <summary>Properties for an OpenGraph image</summary>
[<CLIMutable>]
type OpenGraphImage = {
/// <summary>The URL for this image</summary>
Url: string
/// <summary>The URL for this image for sites that require https</summary>
SecureUrl: string option
/// <summary>The MIME type of the image</summary>
Type: string option
/// <summary>The image width (in pixels)</summary>
Width: int option
/// <summary>The image height (in pixels)</summary>
Height: int option
/// <summary>Alternative text for the image</summary>
Alt: string option
} with
/// <summary>An empty image file</summary>
static member Empty =
{ Url = ""
SecureUrl = None
Type = None
Width = None
Height = None
Alt = None }
/// <summary>Properties for an OpenGraph video</summary>
[<CLIMutable>]
type OpenGraphVideo = {
/// <summary>The URL for this video</summary>
Url: string
/// <summary>The URL for this video for sites that require https</summary>
SecureUrl: string option
/// <summary>The MIME type of the video</summary>
Type: string option
/// <summary>The video width (in pixels)</summary>
Width: int option
/// <summary>The video height (in pixels)</summary>
Height: int option
} with
/// <summary>An empty video file</summary>
static member Empty =
{ Url = ""
SecureUrl = None
Type = None
Width = None
Height = None }
/// <summary>Valid <c>og:type</c> values</summary>
[<Struct>]
type OpenGraphType =
| Article
| Book
| MusicAlbum
| MusicPlaylist
| MusicRadioStation
| MusicSong
| PaymentLink
| Profile
| VideoEpisode
| VideoMovie
| VideoOther
| VideoTvShow
| Website
/// <summary>Parse a string into an OpenGraph type</summary>
/// <param name="typ">The string to be parsed</param>
/// <returns>The <c>OpenGraphType</c> parsed from the string</returns>
/// <exception cref="InvalidArgumentException">If the string is not valid</exception>
static member Parse typ =
match typ with
| "article" -> Article
| "book" -> Book
| "music.album" -> MusicAlbum
| "music.playlist" -> MusicPlaylist
| "music.radio_station" -> MusicRadioStation
| "music.song" -> MusicSong
| "payment.link" -> PaymentLink
| "profile" -> Profile
| "video.episode" -> VideoEpisode
| "video.movie" -> VideoMovie
| "video.other" -> VideoOther
| "video.tv_show" -> VideoTvShow
| "website" -> Website
| _ -> invalidArg (nameof typ) $"{typ} is not a valid OpenGraph type"
override this.ToString() =
match this with
| Article -> "article"
| Book -> "book"
| MusicAlbum -> "music.album"
| MusicPlaylist -> "music.playlist"
| MusicRadioStation -> "music.radio_station"
| MusicSong -> "music.song"
| PaymentLink -> "payment.link"
| Profile -> "profile"
| VideoEpisode -> "video.episode"
| VideoMovie -> "video.movie"
| VideoOther -> "video.other"
| VideoTvShow -> "video.tv_show"
| Website -> "website"
/// <summary>Top-level properties for OpenGraph</summary>
[<CLIMutable>]
type OpenGraphTopLevel = {
/// <summary>The type of object represented</summary>
Type: OpenGraphType
/// <summary>An image representing the object</summary>
Image: OpenGraphImage
/// <summary>An audio file associated with the object</summary>
Audio: OpenGraphAudio option
/// <summary>A short description of the object</summary>
Description: string option
/// <summary>The article (a, an, the, etc.) which should be used to refer to this object</summary>
Determiner: string option
/// <summary>The primary locale of the content of the object</summary>
Locale: string option
/// <summary>Other locales in which the content of the object is available</summary>
LocaleAlternate: string list option
/// <summary>A video file assigned with the object</summary>
Video: OpenGraphVideo option
}
/// <summary>A permanent link</summary> /// <summary>A permanent link</summary>
[<Struct>] [<Struct>]
type Permalink = type Permalink =