2022-06-23 00:35:12 +00:00
|
|
|
namespace MyWebLog.ViewModels
|
|
|
|
|
|
|
|
open System
|
|
|
|
open MyWebLog
|
2022-08-21 22:56:18 +00:00
|
|
|
open NodaTime
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Helper functions for view models
|
|
|
|
[<AutoOpen>]
|
|
|
|
module private Helpers =
|
|
|
|
|
|
|
|
/// Create a string option if a string is blank
|
2023-12-16 22:59:33 +00:00
|
|
|
let noneIfBlank it =
|
2023-12-13 20:43:35 +00:00
|
|
|
match (defaultArg (Option.ofObj it) "").Trim() with "" -> None | trimmed -> Some trimmed
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
2022-07-29 00:36:02 +00:00
|
|
|
/// Helper functions that are needed outside this file
|
|
|
|
[<AutoOpen>]
|
|
|
|
module PublicHelpers =
|
|
|
|
|
|
|
|
/// If the web log is not being served from the domain root, add the path information to relative URLs in page and
|
|
|
|
/// post text
|
2023-12-16 22:59:33 +00:00
|
|
|
let addBaseToRelativeUrls extra (text: string) =
|
2022-07-29 00:36:02 +00:00
|
|
|
if extra = "" then text
|
2023-12-16 22:59:33 +00:00
|
|
|
else text.Replace("href=\"/", $"href=\"{extra}/").Replace("src=\"/", $"src=\"{extra}/")
|
2022-07-29 00:36:02 +00:00
|
|
|
|
|
|
|
|
2022-06-29 02:18:56 +00:00
|
|
|
/// The model used to display the admin dashboard
|
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-13 20:43:35 +00:00
|
|
|
type DashboardModel = {
|
|
|
|
/// The number of published posts
|
2023-12-16 22:59:33 +00:00
|
|
|
Posts: int
|
2022-06-29 02:18:56 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The number of post drafts
|
2023-12-16 22:59:33 +00:00
|
|
|
Drafts: int
|
2022-06-29 02:18:56 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The number of pages
|
2023-12-16 22:59:33 +00:00
|
|
|
Pages: int
|
2022-06-29 02:18:56 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The number of pages in the page list
|
2023-12-16 22:59:33 +00:00
|
|
|
ListedPages: int
|
2022-06-29 02:18:56 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The number of categories
|
2023-12-16 22:59:33 +00:00
|
|
|
Categories: int
|
2022-06-29 02:18:56 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The top-level categories
|
2023-12-16 22:59:33 +00:00
|
|
|
TopLevelCategories: int
|
2023-12-13 20:43:35 +00:00
|
|
|
}
|
2022-06-29 02:18:56 +00:00
|
|
|
|
|
|
|
|
2022-06-23 00:35:12 +00:00
|
|
|
/// Details about a category, used to display category lists
|
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-13 20:43:35 +00:00
|
|
|
type DisplayCategory = {
|
|
|
|
/// The ID of the category
|
2023-12-16 22:59:33 +00:00
|
|
|
Id: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The slug for the category
|
2023-12-16 22:59:33 +00:00
|
|
|
Slug: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The name of the category
|
2023-12-16 22:59:33 +00:00
|
|
|
Name: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// A description of the category
|
2023-12-16 22:59:33 +00:00
|
|
|
Description: string option
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The parent category names for this (sub)category
|
2023-12-16 22:59:33 +00:00
|
|
|
ParentNames: string array
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The number of posts in this category
|
2023-12-16 22:59:33 +00:00
|
|
|
PostCount: int
|
2023-12-13 20:43:35 +00:00
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// A display version of a custom feed definition
|
2023-12-13 20:43:35 +00:00
|
|
|
type DisplayCustomFeed = {
|
|
|
|
/// The ID of the custom feed
|
2023-12-16 17:24:45 +00:00
|
|
|
Id: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The source of the custom feed
|
2023-12-16 17:24:45 +00:00
|
|
|
Source: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The relative path at which the custom feed is served
|
2023-12-16 17:24:45 +00:00
|
|
|
Path: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// Whether this custom feed is for a podcast
|
2023-12-16 17:24:45 +00:00
|
|
|
IsPodcast: bool
|
2023-12-16 22:59:33 +00:00
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a display version from a custom feed
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromFeed (cats: DisplayCategory array) (feed: CustomFeed) =
|
2022-06-23 00:35:12 +00:00
|
|
|
let source =
|
2022-07-19 00:05:10 +00:00
|
|
|
match feed.Source with
|
2022-07-18 03:10:30 +00:00
|
|
|
| Category (CategoryId catId) -> $"Category: {(cats |> Array.find (fun cat -> cat.Id = catId)).Name}"
|
2022-06-23 00:35:12 +00:00
|
|
|
| Tag tag -> $"Tag: {tag}"
|
2023-12-16 17:24:45 +00:00
|
|
|
{ Id = string feed.Id
|
2022-07-20 02:51:51 +00:00
|
|
|
Source = source
|
2023-12-16 17:24:45 +00:00
|
|
|
Path = string feed.Path
|
2022-07-20 02:51:51 +00:00
|
|
|
IsPodcast = Option.isSome feed.Podcast
|
2022-06-23 00:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Details about a page used to display page lists
|
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-16 19:05:45 +00:00
|
|
|
type DisplayPage = {
|
|
|
|
/// The ID of this page
|
|
|
|
Id: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 19:05:45 +00:00
|
|
|
/// The ID of the author of this page
|
|
|
|
AuthorId: string
|
|
|
|
|
|
|
|
/// The title of the page
|
|
|
|
Title: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 19:05:45 +00:00
|
|
|
/// The link at which this page is displayed
|
|
|
|
Permalink: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 19:05:45 +00:00
|
|
|
/// When this page was published
|
|
|
|
PublishedOn: DateTime
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 19:05:45 +00:00
|
|
|
/// When this page was last updated
|
|
|
|
UpdatedOn: DateTime
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 19:05:45 +00:00
|
|
|
/// Whether this page shows as part of the web log's navigation
|
|
|
|
IsInPageList: bool
|
|
|
|
|
|
|
|
/// Is this the default page?
|
|
|
|
IsDefault: bool
|
|
|
|
|
|
|
|
/// The text of the page
|
|
|
|
Text: string
|
|
|
|
|
|
|
|
/// The metadata for the page
|
|
|
|
Metadata: MetaItem list
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a minimal display page (no text or metadata) from a database page
|
2023-12-16 19:05:45 +00:00
|
|
|
static member FromPageMinimal (webLog: WebLog) (page: Page) = {
|
2023-12-16 17:24:45 +00:00
|
|
|
Id = string page.Id
|
|
|
|
AuthorId = string page.AuthorId
|
2023-12-16 03:46:12 +00:00
|
|
|
Title = page.Title
|
2023-12-16 17:24:45 +00:00
|
|
|
Permalink = string page.Permalink
|
2023-12-16 19:05:45 +00:00
|
|
|
PublishedOn = webLog.LocalTime page.PublishedOn
|
|
|
|
UpdatedOn = webLog.LocalTime page.UpdatedOn
|
2023-12-16 03:46:12 +00:00
|
|
|
IsInPageList = page.IsInPageList
|
2023-12-16 17:24:45 +00:00
|
|
|
IsDefault = string page.Id = webLog.DefaultPage
|
2023-12-16 03:46:12 +00:00
|
|
|
Text = ""
|
|
|
|
Metadata = []
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a display page from a database page
|
2023-12-16 19:05:45 +00:00
|
|
|
static member FromPage webLog page =
|
|
|
|
{ DisplayPage.FromPageMinimal webLog page with
|
|
|
|
Text = addBaseToRelativeUrls webLog.ExtraPath page.Text
|
|
|
|
Metadata = page.Metadata
|
2022-06-23 00:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-15 03:25:29 +00:00
|
|
|
/// Information about a revision used for display
|
2022-07-18 03:10:30 +00:00
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-13 20:43:35 +00:00
|
|
|
type DisplayRevision = {
|
|
|
|
/// The as-of date/time for the revision
|
2023-12-16 19:05:45 +00:00
|
|
|
AsOf: DateTime
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The as-of date/time for the revision in the web log's local time zone
|
2023-12-16 19:05:45 +00:00
|
|
|
AsOfLocal: DateTime
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The format of the text of the revision
|
2023-12-16 19:05:45 +00:00
|
|
|
Format: string
|
2023-12-16 22:59:33 +00:00
|
|
|
} with
|
2023-12-13 20:43:35 +00:00
|
|
|
|
2022-07-15 03:25:29 +00:00
|
|
|
/// Create a display revision from an actual revision
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromRevision (webLog: WebLog) (rev : Revision) = {
|
|
|
|
AsOf = rev.AsOf.ToDateTimeUtc()
|
|
|
|
AsOfLocal = webLog.LocalTime rev.AsOf
|
|
|
|
Format = rev.Text.SourceType
|
|
|
|
}
|
2022-07-15 03:25:29 +00:00
|
|
|
|
|
|
|
|
2022-06-29 02:18:56 +00:00
|
|
|
open System.IO
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2022-07-23 01:19:19 +00:00
|
|
|
/// Information about a theme used for display
|
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-13 20:43:35 +00:00
|
|
|
type DisplayTheme = {
|
|
|
|
/// The ID / path slug of the theme
|
2023-12-16 17:24:45 +00:00
|
|
|
Id: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The name of the theme
|
2023-12-16 17:24:45 +00:00
|
|
|
Name: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The version of the theme
|
2023-12-16 17:24:45 +00:00
|
|
|
Version: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// How many templates are contained in the theme
|
2023-12-16 17:24:45 +00:00
|
|
|
TemplateCount: int
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// Whether the theme is in use by any web logs
|
2023-12-16 17:24:45 +00:00
|
|
|
IsInUse: bool
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// Whether the theme .zip file exists on the filesystem
|
2023-12-16 17:24:45 +00:00
|
|
|
IsOnDisk: bool
|
2023-12-16 22:59:33 +00:00
|
|
|
} with
|
2022-07-23 01:19:19 +00:00
|
|
|
|
|
|
|
/// Create a display theme from a theme
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromTheme inUseFunc (theme: Theme) = {
|
|
|
|
Id = string theme.Id
|
|
|
|
Name = theme.Name
|
|
|
|
Version = theme.Version
|
|
|
|
TemplateCount = List.length theme.Templates
|
|
|
|
IsInUse = inUseFunc theme.Id
|
|
|
|
IsOnDisk = File.Exists $"{theme.Id}-theme.zip"
|
|
|
|
}
|
2022-07-23 01:19:19 +00:00
|
|
|
|
|
|
|
|
2022-06-29 02:18:56 +00:00
|
|
|
/// Information about an uploaded file used for display
|
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-13 20:43:35 +00:00
|
|
|
type DisplayUpload = {
|
|
|
|
/// The ID of the uploaded file
|
2023-12-16 17:24:45 +00:00
|
|
|
Id: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The name of the uploaded file
|
2023-12-16 17:24:45 +00:00
|
|
|
Name: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The path at which the file is served
|
2023-12-16 17:24:45 +00:00
|
|
|
Path: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The date/time the file was updated
|
2023-12-16 17:24:45 +00:00
|
|
|
UpdatedOn: DateTime option
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// The source for this file (created from UploadDestination DU)
|
2023-12-16 17:24:45 +00:00
|
|
|
Source: string
|
2023-12-16 22:59:33 +00:00
|
|
|
} with
|
2022-06-29 02:18:56 +00:00
|
|
|
|
|
|
|
/// Create a display uploaded file
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromUpload (webLog: WebLog) (source: UploadDestination) (upload: Upload) =
|
2023-12-16 17:24:45 +00:00
|
|
|
let path = string upload.Path
|
2022-06-29 02:18:56 +00:00
|
|
|
let name = Path.GetFileName path
|
2023-12-16 17:24:45 +00:00
|
|
|
{ Id = string upload.Id
|
2022-07-20 02:51:51 +00:00
|
|
|
Name = name
|
2023-12-16 17:24:45 +00:00
|
|
|
Path = path.Replace(name, "")
|
2023-12-16 19:05:45 +00:00
|
|
|
UpdatedOn = Some (webLog.LocalTime upload.UpdatedOn)
|
2023-12-16 17:24:45 +00:00
|
|
|
Source = string source
|
2022-07-20 02:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// View model to display a user's information
|
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-13 20:43:35 +00:00
|
|
|
type DisplayUser = {
|
|
|
|
/// The ID of the user
|
2023-12-16 17:24:45 +00:00
|
|
|
Id: string
|
2022-07-20 02:51:51 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The user name (e-mail address)
|
2023-12-16 17:24:45 +00:00
|
|
|
Email: string
|
2022-07-20 02:51:51 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The user's first name
|
2023-12-16 17:24:45 +00:00
|
|
|
FirstName: string
|
2022-07-20 02:51:51 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The user's last name
|
2023-12-16 17:24:45 +00:00
|
|
|
LastName: string
|
2022-07-20 02:51:51 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The user's preferred name
|
2023-12-16 17:24:45 +00:00
|
|
|
PreferredName: string
|
2022-07-20 02:51:51 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The URL of the user's personal site
|
2023-12-16 17:24:45 +00:00
|
|
|
Url: string
|
2022-07-20 02:51:51 +00:00
|
|
|
|
2023-12-13 20:43:35 +00:00
|
|
|
/// The user's access level
|
2023-12-16 17:24:45 +00:00
|
|
|
AccessLevel: string
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// When the user was created
|
2023-12-16 17:24:45 +00:00
|
|
|
CreatedOn: DateTime
|
2023-12-13 20:43:35 +00:00
|
|
|
|
|
|
|
/// When the user last logged on
|
2023-12-16 17:24:45 +00:00
|
|
|
LastSeenOn: Nullable<DateTime>
|
2023-12-16 22:59:33 +00:00
|
|
|
} with
|
2022-07-20 02:51:51 +00:00
|
|
|
|
|
|
|
/// Construct a displayed user from a web log user
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromUser (webLog: WebLog) (user: WebLogUser) = {
|
2023-12-16 19:05:45 +00:00
|
|
|
Id = string user.Id
|
|
|
|
Email = user.Email
|
|
|
|
FirstName = user.FirstName
|
|
|
|
LastName = user.LastName
|
|
|
|
PreferredName = user.PreferredName
|
|
|
|
Url = defaultArg user.Url ""
|
|
|
|
AccessLevel = string user.AccessLevel
|
|
|
|
CreatedOn = webLog.LocalTime user.CreatedOn
|
|
|
|
LastSeenOn = user.LastSeenOn |> Option.map webLog.LocalTime |> Option.toNullable
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// View model for editing categories
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 17:24:45 +00:00
|
|
|
type EditCategoryModel = {
|
|
|
|
/// The ID of the category being edited
|
|
|
|
CategoryId: string
|
|
|
|
|
|
|
|
/// The name of the category
|
|
|
|
Name: string
|
|
|
|
|
|
|
|
/// The category's URL slug
|
|
|
|
Slug: string
|
|
|
|
|
|
|
|
/// A description of the category (optional)
|
|
|
|
Description: string
|
|
|
|
|
|
|
|
/// The ID of the category for which this is a subcategory (optional)
|
|
|
|
ParentId: string
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create an edit model from an existing category
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromCategory (cat: Category) = {
|
|
|
|
CategoryId = string cat.Id
|
|
|
|
Name = cat.Name
|
|
|
|
Slug = cat.Slug
|
|
|
|
Description = defaultArg cat.Description ""
|
|
|
|
ParentId = cat.ParentId |> Option.map string |> Option.defaultValue ""
|
|
|
|
}
|
2022-07-21 03:13:16 +00:00
|
|
|
|
|
|
|
/// Is this a new category?
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.IsNew =
|
|
|
|
this.CategoryId = "new"
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// View model to edit a custom RSS feed
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type EditCustomFeedModel = {
|
|
|
|
/// The ID of the feed being editing
|
|
|
|
Id: string
|
|
|
|
|
|
|
|
/// The type of source for this feed ("category" or "tag")
|
|
|
|
SourceType: string
|
|
|
|
|
|
|
|
/// The category ID or tag on which this feed is based
|
|
|
|
SourceValue: string
|
|
|
|
|
|
|
|
/// The relative path at which this feed is served
|
|
|
|
Path: string
|
|
|
|
|
|
|
|
/// Whether this feed defines a podcast
|
|
|
|
IsPodcast: bool
|
|
|
|
|
|
|
|
/// The title of the podcast
|
|
|
|
Title: string
|
|
|
|
|
|
|
|
/// A subtitle for the podcast
|
|
|
|
Subtitle: string
|
|
|
|
|
|
|
|
/// The number of items in the podcast feed
|
|
|
|
ItemsInFeed: int
|
|
|
|
|
|
|
|
/// A summary of the podcast (iTunes field)
|
|
|
|
Summary: string
|
|
|
|
|
|
|
|
/// The display name of the podcast author (iTunes field)
|
|
|
|
DisplayedAuthor: string
|
|
|
|
|
|
|
|
/// The e-mail address of the user who registered the podcast at iTunes
|
|
|
|
Email: string
|
|
|
|
|
|
|
|
/// The link to the image for the podcast
|
|
|
|
ImageUrl: string
|
|
|
|
|
|
|
|
/// The category from Apple Podcasts (iTunes) under which this podcast is categorized
|
|
|
|
AppleCategory: string
|
|
|
|
|
|
|
|
/// A further refinement of the categorization of this podcast (Apple Podcasts/iTunes field / values)
|
|
|
|
AppleSubcategory: string
|
|
|
|
|
|
|
|
/// The explictness rating (iTunes field)
|
|
|
|
Explicit: string
|
|
|
|
|
|
|
|
/// The default media type for files in this podcast
|
|
|
|
DefaultMediaType: string
|
|
|
|
|
|
|
|
/// The base URL for relative URL media files for this podcast (optional; defaults to web log base)
|
|
|
|
MediaBaseUrl: string
|
|
|
|
|
|
|
|
/// The URL for funding information for the podcast
|
|
|
|
FundingUrl: string
|
|
|
|
|
|
|
|
/// The text for the funding link
|
|
|
|
FundingText: string
|
|
|
|
|
|
|
|
/// A unique identifier to follow this podcast
|
|
|
|
PodcastGuid: string
|
|
|
|
|
|
|
|
/// The medium for the content of this podcast
|
|
|
|
Medium: string
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// An empty custom feed model
|
2023-12-16 22:59:33 +00:00
|
|
|
static member Empty = {
|
|
|
|
Id = ""
|
|
|
|
SourceType = "category"
|
|
|
|
SourceValue = ""
|
|
|
|
Path = ""
|
|
|
|
IsPodcast = false
|
|
|
|
Title = ""
|
|
|
|
Subtitle = ""
|
|
|
|
ItemsInFeed = 25
|
|
|
|
Summary = ""
|
|
|
|
DisplayedAuthor = ""
|
|
|
|
Email = ""
|
|
|
|
ImageUrl = ""
|
|
|
|
AppleCategory = ""
|
|
|
|
AppleSubcategory = ""
|
|
|
|
Explicit = "no"
|
|
|
|
DefaultMediaType = "audio/mpeg"
|
|
|
|
MediaBaseUrl = ""
|
|
|
|
FundingUrl = ""
|
|
|
|
FundingText = ""
|
|
|
|
PodcastGuid = ""
|
|
|
|
Medium = ""
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a model from a custom feed
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromFeed (feed: CustomFeed) =
|
2022-06-23 00:35:12 +00:00
|
|
|
let rss =
|
2023-12-16 22:59:33 +00:00
|
|
|
{ EditCustomFeedModel.Empty with
|
2023-12-16 17:24:45 +00:00
|
|
|
Id = string feed.Id
|
2022-07-19 00:05:10 +00:00
|
|
|
SourceType = match feed.Source with Category _ -> "category" | Tag _ -> "tag"
|
|
|
|
SourceValue = match feed.Source with Category (CategoryId catId) -> catId | Tag tag -> tag
|
2023-12-16 22:59:33 +00:00
|
|
|
Path = string feed.Path }
|
2022-07-19 00:05:10 +00:00
|
|
|
match feed.Podcast with
|
2022-06-23 00:35:12 +00:00
|
|
|
| Some p ->
|
|
|
|
{ rss with
|
2022-07-19 00:05:10 +00:00
|
|
|
IsPodcast = true
|
|
|
|
Title = p.Title
|
|
|
|
Subtitle = defaultArg p.Subtitle ""
|
|
|
|
ItemsInFeed = p.ItemsInFeed
|
|
|
|
Summary = p.Summary
|
|
|
|
DisplayedAuthor = p.DisplayedAuthor
|
|
|
|
Email = p.Email
|
2023-12-16 17:24:45 +00:00
|
|
|
ImageUrl = string p.ImageUrl
|
2022-07-19 00:05:10 +00:00
|
|
|
AppleCategory = p.AppleCategory
|
|
|
|
AppleSubcategory = defaultArg p.AppleSubcategory ""
|
2023-12-16 17:24:45 +00:00
|
|
|
Explicit = string p.Explicit
|
2022-07-19 00:05:10 +00:00
|
|
|
DefaultMediaType = defaultArg p.DefaultMediaType ""
|
|
|
|
MediaBaseUrl = defaultArg p.MediaBaseUrl ""
|
|
|
|
FundingUrl = defaultArg p.FundingUrl ""
|
|
|
|
FundingText = defaultArg p.FundingText ""
|
2023-12-16 03:46:12 +00:00
|
|
|
PodcastGuid = p.PodcastGuid |> Option.map _.ToString().ToLowerInvariant() |> Option.defaultValue ""
|
2023-12-16 22:59:33 +00:00
|
|
|
Medium = p.Medium |> Option.map string |> Option.defaultValue "" }
|
2022-06-23 00:35:12 +00:00
|
|
|
| None -> rss
|
|
|
|
|
|
|
|
/// Update a feed with values from this model
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.UpdateFeed (feed: CustomFeed) =
|
2022-06-23 00:35:12 +00:00
|
|
|
{ feed with
|
2022-07-19 00:05:10 +00:00
|
|
|
Source = if this.SourceType = "tag" then Tag this.SourceValue else Category (CategoryId this.SourceValue)
|
|
|
|
Path = Permalink this.Path
|
|
|
|
Podcast =
|
2022-07-18 03:10:30 +00:00
|
|
|
if this.IsPodcast then
|
2022-06-23 00:35:12 +00:00
|
|
|
Some {
|
2022-07-19 00:05:10 +00:00
|
|
|
Title = this.Title
|
|
|
|
Subtitle = noneIfBlank this.Subtitle
|
|
|
|
ItemsInFeed = this.ItemsInFeed
|
|
|
|
Summary = this.Summary
|
|
|
|
DisplayedAuthor = this.DisplayedAuthor
|
|
|
|
Email = this.Email
|
|
|
|
ImageUrl = Permalink this.ImageUrl
|
|
|
|
AppleCategory = this.AppleCategory
|
|
|
|
AppleSubcategory = noneIfBlank this.AppleSubcategory
|
2023-12-15 04:49:38 +00:00
|
|
|
Explicit = ExplicitRating.Parse this.Explicit
|
2022-07-19 00:05:10 +00:00
|
|
|
DefaultMediaType = noneIfBlank this.DefaultMediaType
|
|
|
|
MediaBaseUrl = noneIfBlank this.MediaBaseUrl
|
|
|
|
PodcastGuid = noneIfBlank this.PodcastGuid |> Option.map Guid.Parse
|
|
|
|
FundingUrl = noneIfBlank this.FundingUrl
|
|
|
|
FundingText = noneIfBlank this.FundingText
|
2023-12-16 22:59:33 +00:00
|
|
|
Medium = noneIfBlank this.Medium |> Option.map PodcastMedium.Parse }
|
2022-06-23 00:35:12 +00:00
|
|
|
else
|
2023-12-16 22:59:33 +00:00
|
|
|
None }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2022-07-19 00:05:10 +00:00
|
|
|
|
|
|
|
/// View model for a user to edit their own information
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type EditMyInfoModel = {
|
|
|
|
/// The user's first name
|
|
|
|
FirstName: string
|
|
|
|
|
|
|
|
/// The user's last name
|
|
|
|
LastName: string
|
|
|
|
|
|
|
|
/// The user's preferred name
|
|
|
|
PreferredName: string
|
|
|
|
|
|
|
|
/// A new password for the user
|
|
|
|
NewPassword: string
|
|
|
|
|
|
|
|
/// A new password for the user, confirmed
|
|
|
|
NewPasswordConfirm: string
|
|
|
|
} with
|
2022-07-19 00:05:10 +00:00
|
|
|
|
|
|
|
/// Create an edit model from a user
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromUser (user: WebLogUser) = {
|
|
|
|
FirstName = user.FirstName
|
|
|
|
LastName = user.LastName
|
|
|
|
PreferredName = user.PreferredName
|
|
|
|
NewPassword = ""
|
|
|
|
NewPasswordConfirm = ""
|
|
|
|
}
|
2022-07-19 00:05:10 +00:00
|
|
|
|
|
|
|
|
2022-06-23 00:35:12 +00:00
|
|
|
/// View model to edit a page
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 03:46:12 +00:00
|
|
|
type EditPageModel = {
|
|
|
|
/// The ID of the page being edited
|
|
|
|
PageId: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The title of the page
|
|
|
|
Title: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The permalink for the page
|
|
|
|
Permalink: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The template to use to display the page
|
|
|
|
Template: string
|
|
|
|
|
|
|
|
/// Whether this page is shown in the page list
|
|
|
|
IsShownInPageList: bool
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The source format for the text
|
|
|
|
Source: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The text of the page
|
|
|
|
Text: string
|
|
|
|
|
|
|
|
/// Names of metadata items
|
|
|
|
MetaNames: string array
|
|
|
|
|
|
|
|
/// Values of metadata items
|
|
|
|
MetaValues: string array
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create an edit model from an existing page
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromPage (page: Page) =
|
2022-06-23 00:35:12 +00:00
|
|
|
let latest =
|
2023-12-16 03:46:12 +00:00
|
|
|
match page.Revisions |> List.sortByDescending _.AsOf |> List.tryHead with
|
2022-06-23 00:35:12 +00:00
|
|
|
| Some rev -> rev
|
2023-12-16 03:46:12 +00:00
|
|
|
| None -> Revision.Empty
|
|
|
|
let page = if page.Metadata |> List.isEmpty then { page with Metadata = [ MetaItem.Empty ] } else page
|
2023-12-16 17:24:45 +00:00
|
|
|
{ PageId = string page.Id
|
2022-07-20 02:51:51 +00:00
|
|
|
Title = page.Title
|
2023-12-16 17:24:45 +00:00
|
|
|
Permalink = string page.Permalink
|
2022-07-20 02:51:51 +00:00
|
|
|
Template = defaultArg page.Template ""
|
|
|
|
IsShownInPageList = page.IsInPageList
|
2023-12-16 03:46:12 +00:00
|
|
|
Source = latest.Text.SourceType
|
|
|
|
Text = latest.Text.Text
|
|
|
|
MetaNames = page.Metadata |> List.map _.Name |> Array.ofList
|
|
|
|
MetaValues = page.Metadata |> List.map _.Value |> Array.ofList
|
2022-06-23 00:35:12 +00:00
|
|
|
}
|
2022-07-20 00:59:53 +00:00
|
|
|
|
|
|
|
/// Whether this is a new page
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.IsNew =
|
|
|
|
this.PageId = "new"
|
2022-07-20 00:59:53 +00:00
|
|
|
|
|
|
|
/// Update a page with values from this model
|
2023-12-16 03:46:12 +00:00
|
|
|
member this.UpdatePage (page: Page) now =
|
|
|
|
let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" }
|
2022-07-20 00:59:53 +00:00
|
|
|
// Detect a permalink change, and add the prior one to the prior list
|
2023-12-16 17:24:45 +00:00
|
|
|
match string page.Permalink with
|
2022-07-20 00:59:53 +00:00
|
|
|
| "" -> page
|
|
|
|
| link when link = this.Permalink -> page
|
|
|
|
| _ -> { page with PriorPermalinks = page.Permalink :: page.PriorPermalinks }
|
|
|
|
|> function
|
|
|
|
| page ->
|
|
|
|
{ page with
|
|
|
|
Title = this.Title
|
|
|
|
Permalink = Permalink this.Permalink
|
|
|
|
UpdatedOn = now
|
|
|
|
IsInPageList = this.IsShownInPageList
|
|
|
|
Template = match this.Template with "" -> None | tmpl -> Some tmpl
|
2023-12-16 03:46:12 +00:00
|
|
|
Text = revision.Text.AsHtml()
|
2022-07-20 00:59:53 +00:00
|
|
|
Metadata = Seq.zip this.MetaNames this.MetaValues
|
|
|
|
|> Seq.filter (fun it -> fst it > "")
|
|
|
|
|> Seq.map (fun it -> { Name = fst it; Value = snd it })
|
2023-12-16 22:59:33 +00:00
|
|
|
|> Seq.sortBy (fun it -> $"{it.Name.ToLower()} {it.Value.ToLower()}")
|
2022-07-20 00:59:53 +00:00
|
|
|
|> List.ofSeq
|
|
|
|
Revisions = match page.Revisions |> List.tryHead with
|
|
|
|
| Some r when r.Text = revision.Text -> page.Revisions
|
2023-12-16 22:59:33 +00:00
|
|
|
| _ -> revision :: page.Revisions }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// View model to edit a post
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 03:46:12 +00:00
|
|
|
type EditPostModel = {
|
|
|
|
/// The ID of the post being edited
|
|
|
|
PostId: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The title of the post
|
|
|
|
Title: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The permalink for the post
|
|
|
|
Permalink: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The source format for the text
|
|
|
|
Source: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 03:46:12 +00:00
|
|
|
/// The text of the post
|
|
|
|
Text: string
|
|
|
|
|
|
|
|
/// The tags for the post
|
|
|
|
Tags: string
|
|
|
|
|
|
|
|
/// The template used to display the post
|
|
|
|
Template: string
|
|
|
|
|
|
|
|
/// The category IDs for the post
|
|
|
|
CategoryIds: string array
|
|
|
|
|
|
|
|
/// The post status
|
|
|
|
Status: string
|
|
|
|
|
|
|
|
/// Whether this post should be published
|
|
|
|
DoPublish: bool
|
|
|
|
|
|
|
|
/// Names of metadata items
|
|
|
|
MetaNames: string array
|
|
|
|
|
|
|
|
/// Values of metadata items
|
|
|
|
MetaValues: string array
|
|
|
|
|
|
|
|
/// Whether to override the published date/time
|
|
|
|
SetPublished: bool
|
|
|
|
|
|
|
|
/// The published date/time to override
|
|
|
|
PubOverride: Nullable<DateTime>
|
|
|
|
|
|
|
|
/// Whether all revisions should be purged and the override date set as the updated date as well
|
|
|
|
SetUpdated: bool
|
|
|
|
|
|
|
|
/// Whether this post has a podcast episode
|
|
|
|
IsEpisode: bool
|
|
|
|
|
|
|
|
/// The URL for the media for this episode (may be permalink)
|
|
|
|
Media: string
|
|
|
|
|
|
|
|
/// The size (in bytes) of the media for this episode
|
|
|
|
Length: int64
|
|
|
|
|
|
|
|
/// The duration of the media for this episode
|
|
|
|
Duration: string
|
|
|
|
|
|
|
|
/// The media type (optional, defaults to podcast-defined media type)
|
|
|
|
MediaType: string
|
|
|
|
|
|
|
|
/// The URL for the image for this episode (may be permalink; optional, defaults to podcast image)
|
|
|
|
ImageUrl: string
|
|
|
|
|
|
|
|
/// A subtitle for the episode (optional)
|
|
|
|
Subtitle: string
|
|
|
|
|
|
|
|
/// The explicit rating for this episode (optional, defaults to podcast setting)
|
|
|
|
Explicit: string
|
|
|
|
|
|
|
|
/// The URL for the chapter file for the episode (may be permalink; optional)
|
|
|
|
ChapterFile: string
|
|
|
|
|
|
|
|
/// The type of the chapter file (optional; defaults to application/json+chapters if chapterFile is provided)
|
|
|
|
ChapterType: string
|
|
|
|
|
|
|
|
/// The URL for the transcript (may be permalink; optional)
|
|
|
|
TranscriptUrl: string
|
|
|
|
|
|
|
|
/// The MIME type for the transcript (optional, recommended if transcriptUrl is provided)
|
|
|
|
TranscriptType: string
|
|
|
|
|
|
|
|
/// The language of the transcript (optional)
|
|
|
|
TranscriptLang: string
|
|
|
|
|
|
|
|
/// Whether the provided transcript should be presented as captions
|
|
|
|
TranscriptCaptions: bool
|
|
|
|
|
|
|
|
/// The season number (optional)
|
|
|
|
SeasonNumber: int
|
|
|
|
|
|
|
|
/// A description of this season (optional, ignored if season number is not provided)
|
|
|
|
SeasonDescription: string
|
|
|
|
|
|
|
|
/// The episode number (decimal; optional)
|
|
|
|
EpisodeNumber: string
|
|
|
|
|
|
|
|
/// A description of this episode (optional, ignored if episode number is not provided)
|
|
|
|
EpisodeDescription: string
|
|
|
|
} with
|
2022-06-27 11:36:29 +00:00
|
|
|
|
2022-06-23 00:35:12 +00:00
|
|
|
/// Create an edit model from an existing past
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromPost (webLog: WebLog) (post: Post) =
|
2022-06-23 00:35:12 +00:00
|
|
|
let latest =
|
2023-12-16 03:46:12 +00:00
|
|
|
match post.Revisions |> List.sortByDescending _.AsOf |> List.tryHead with
|
2022-06-23 00:35:12 +00:00
|
|
|
| Some rev -> rev
|
2023-12-16 03:46:12 +00:00
|
|
|
| None -> Revision.Empty
|
|
|
|
let post = if post.Metadata |> List.isEmpty then { post with Metadata = [ MetaItem.Empty ] } else post
|
2023-12-15 04:49:38 +00:00
|
|
|
let episode = defaultArg post.Episode Episode.Empty
|
2023-12-16 17:24:45 +00:00
|
|
|
{ PostId = string post.Id
|
2022-07-20 02:51:51 +00:00
|
|
|
Title = post.Title
|
2023-12-16 17:24:45 +00:00
|
|
|
Permalink = string post.Permalink
|
2023-12-16 03:46:12 +00:00
|
|
|
Source = latest.Text.SourceType
|
|
|
|
Text = latest.Text.Text
|
2023-12-16 22:59:33 +00:00
|
|
|
Tags = String.Join(", ", post.Tags)
|
2022-07-20 02:51:51 +00:00
|
|
|
Template = defaultArg post.Template ""
|
2023-12-16 17:24:45 +00:00
|
|
|
CategoryIds = post.CategoryIds |> List.map string |> Array.ofList
|
|
|
|
Status = string post.Status
|
2022-07-20 02:51:51 +00:00
|
|
|
DoPublish = false
|
2023-12-16 03:46:12 +00:00
|
|
|
MetaNames = post.Metadata |> List.map _.Name |> Array.ofList
|
|
|
|
MetaValues = post.Metadata |> List.map _.Value |> Array.ofList
|
2022-07-20 02:51:51 +00:00
|
|
|
SetPublished = false
|
2023-12-16 19:05:45 +00:00
|
|
|
PubOverride = post.PublishedOn |> Option.map webLog.LocalTime |> Option.toNullable
|
2022-07-20 02:51:51 +00:00
|
|
|
SetUpdated = false
|
|
|
|
IsEpisode = Option.isSome post.Episode
|
|
|
|
Media = episode.Media
|
|
|
|
Length = episode.Length
|
2023-12-15 04:49:38 +00:00
|
|
|
Duration = defaultArg (episode.FormatDuration()) ""
|
2022-07-20 02:51:51 +00:00
|
|
|
MediaType = defaultArg episode.MediaType ""
|
|
|
|
ImageUrl = defaultArg episode.ImageUrl ""
|
|
|
|
Subtitle = defaultArg episode.Subtitle ""
|
2023-12-16 17:24:45 +00:00
|
|
|
Explicit = defaultArg (episode.Explicit |> Option.map string) ""
|
2022-07-20 02:51:51 +00:00
|
|
|
ChapterFile = defaultArg episode.ChapterFile ""
|
|
|
|
ChapterType = defaultArg episode.ChapterType ""
|
|
|
|
TranscriptUrl = defaultArg episode.TranscriptUrl ""
|
|
|
|
TranscriptType = defaultArg episode.TranscriptType ""
|
|
|
|
TranscriptLang = defaultArg episode.TranscriptLang ""
|
|
|
|
TranscriptCaptions = defaultArg episode.TranscriptCaptions false
|
|
|
|
SeasonNumber = defaultArg episode.SeasonNumber 0
|
|
|
|
SeasonDescription = defaultArg episode.SeasonDescription ""
|
|
|
|
EpisodeNumber = defaultArg (episode.EpisodeNumber |> Option.map string) ""
|
|
|
|
EpisodeDescription = defaultArg episode.EpisodeDescription ""
|
2022-06-27 11:36:29 +00:00
|
|
|
}
|
|
|
|
|
2022-07-20 00:59:53 +00:00
|
|
|
/// Whether this is a new post
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.IsNew =
|
|
|
|
this.PostId = "new"
|
2022-07-20 00:59:53 +00:00
|
|
|
|
2022-06-27 11:36:29 +00:00
|
|
|
/// Update a post with values from the submitted form
|
2023-12-16 03:46:12 +00:00
|
|
|
member this.UpdatePost (post: Post) now =
|
|
|
|
let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" }
|
2022-07-20 00:59:53 +00:00
|
|
|
// Detect a permalink change, and add the prior one to the prior list
|
2023-12-16 17:24:45 +00:00
|
|
|
match string post.Permalink with
|
2022-07-20 00:59:53 +00:00
|
|
|
| "" -> post
|
|
|
|
| link when link = this.Permalink -> post
|
|
|
|
| _ -> { post with PriorPermalinks = post.Permalink :: post.PriorPermalinks }
|
|
|
|
|> function
|
|
|
|
| post ->
|
|
|
|
{ post with
|
|
|
|
Title = this.Title
|
|
|
|
Permalink = Permalink this.Permalink
|
|
|
|
PublishedOn = if this.DoPublish then Some now else post.PublishedOn
|
|
|
|
UpdatedOn = now
|
2023-12-16 03:46:12 +00:00
|
|
|
Text = revision.Text.AsHtml()
|
2022-07-20 00:59:53 +00:00
|
|
|
Tags = this.Tags.Split ","
|
|
|
|
|> Seq.ofArray
|
2023-12-16 22:59:33 +00:00
|
|
|
|> Seq.map _.Trim().ToLower()
|
2022-07-20 00:59:53 +00:00
|
|
|
|> Seq.filter (fun it -> it <> "")
|
|
|
|
|> Seq.sort
|
|
|
|
|> List.ofSeq
|
2023-12-16 22:59:33 +00:00
|
|
|
Template = match this.Template.Trim() with "" -> None | tmpl -> Some tmpl
|
2022-07-20 00:59:53 +00:00
|
|
|
CategoryIds = this.CategoryIds |> Array.map CategoryId |> List.ofArray
|
|
|
|
Status = if this.DoPublish then Published else post.Status
|
|
|
|
Metadata = Seq.zip this.MetaNames this.MetaValues
|
|
|
|
|> Seq.filter (fun it -> fst it > "")
|
|
|
|
|> Seq.map (fun it -> { Name = fst it; Value = snd it })
|
2023-12-16 22:59:33 +00:00
|
|
|
|> Seq.sortBy (fun it -> $"{it.Name.ToLower()} {it.Value.ToLower()}")
|
2022-07-20 00:59:53 +00:00
|
|
|
|> List.ofSeq
|
|
|
|
Revisions = match post.Revisions |> List.tryHead with
|
|
|
|
| Some r when r.Text = revision.Text -> post.Revisions
|
|
|
|
| _ -> revision :: post.Revisions
|
|
|
|
Episode =
|
|
|
|
if this.IsEpisode then
|
|
|
|
Some {
|
|
|
|
Media = this.Media
|
|
|
|
Length = this.Length
|
2022-08-21 22:56:18 +00:00
|
|
|
Duration = noneIfBlank this.Duration
|
|
|
|
|> Option.map (TimeSpan.Parse >> Duration.FromTimeSpan)
|
2022-07-20 00:59:53 +00:00
|
|
|
MediaType = noneIfBlank this.MediaType
|
|
|
|
ImageUrl = noneIfBlank this.ImageUrl
|
|
|
|
Subtitle = noneIfBlank this.Subtitle
|
2023-12-15 04:49:38 +00:00
|
|
|
Explicit = noneIfBlank this.Explicit |> Option.map ExplicitRating.Parse
|
2023-08-01 02:17:14 +00:00
|
|
|
Chapters = match post.Episode with Some e -> e.Chapters | None -> None
|
2022-07-20 00:59:53 +00:00
|
|
|
ChapterFile = noneIfBlank this.ChapterFile
|
|
|
|
ChapterType = noneIfBlank this.ChapterType
|
|
|
|
TranscriptUrl = noneIfBlank this.TranscriptUrl
|
|
|
|
TranscriptType = noneIfBlank this.TranscriptType
|
|
|
|
TranscriptLang = noneIfBlank this.TranscriptLang
|
|
|
|
TranscriptCaptions = if this.TranscriptCaptions then Some true else None
|
|
|
|
SeasonNumber = if this.SeasonNumber = 0 then None else Some this.SeasonNumber
|
|
|
|
SeasonDescription = noneIfBlank this.SeasonDescription
|
|
|
|
EpisodeNumber = match noneIfBlank this.EpisodeNumber |> Option.map Double.Parse with
|
|
|
|
| Some it when it = 0.0 -> None
|
|
|
|
| Some it -> Some (double it)
|
|
|
|
| None -> None
|
|
|
|
EpisodeDescription = noneIfBlank this.EpisodeDescription
|
|
|
|
}
|
|
|
|
else
|
2023-12-16 22:59:33 +00:00
|
|
|
None }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
2023-07-31 01:00:31 +00:00
|
|
|
/// View model to add/edit a redirect rule
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type EditRedirectRuleModel = {
|
|
|
|
/// The ID (index) of the rule being edited
|
|
|
|
RuleId: int
|
2023-07-31 01:00:31 +00:00
|
|
|
|
2023-12-16 22:59:33 +00:00
|
|
|
/// The "from" side of the rule
|
|
|
|
From: string
|
2023-07-31 01:00:31 +00:00
|
|
|
|
2023-12-16 22:59:33 +00:00
|
|
|
/// The "to" side of the rule
|
|
|
|
To: string
|
2023-07-31 01:00:31 +00:00
|
|
|
|
2023-12-16 22:59:33 +00:00
|
|
|
/// Whether this rule uses a regular expression
|
|
|
|
IsRegex: bool
|
2023-07-31 01:00:31 +00:00
|
|
|
|
2023-12-16 22:59:33 +00:00
|
|
|
/// Whether a new rule should be inserted at the top or appended to the end (ignored for edits)
|
|
|
|
InsertAtTop: bool
|
|
|
|
} with
|
2023-07-31 01:00:31 +00:00
|
|
|
|
|
|
|
/// Create a model from an existing rule
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromRule idx (rule: RedirectRule) = {
|
|
|
|
RuleId = idx
|
|
|
|
From = rule.From
|
|
|
|
To = rule.To
|
|
|
|
IsRegex = rule.IsRegex
|
|
|
|
InsertAtTop = false
|
|
|
|
}
|
2023-07-31 01:00:31 +00:00
|
|
|
|
|
|
|
/// Update a rule with the values from this model
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.ToRule() = {
|
|
|
|
From = this.From
|
|
|
|
To = this.To
|
|
|
|
IsRegex = this.IsRegex
|
|
|
|
}
|
2023-07-31 01:00:31 +00:00
|
|
|
|
|
|
|
|
2022-06-23 00:35:12 +00:00
|
|
|
/// View model to edit RSS settings
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type EditRssModel = {
|
|
|
|
/// Whether the site feed of posts is enabled
|
|
|
|
IsFeedEnabled: bool
|
|
|
|
|
|
|
|
/// The name of the file generated for the site feed
|
|
|
|
FeedName: string
|
|
|
|
|
|
|
|
/// Override the "posts per page" setting for the site feed
|
|
|
|
ItemsInFeed: int
|
|
|
|
|
|
|
|
/// Whether feeds are enabled for all categories
|
|
|
|
IsCategoryEnabled: bool
|
|
|
|
|
|
|
|
/// Whether feeds are enabled for all tags
|
|
|
|
IsTagEnabled: bool
|
|
|
|
|
|
|
|
/// A copyright string to be placed in all feeds
|
|
|
|
Copyright: string
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create an edit model from a set of RSS options
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromRssOptions (rss: RssOptions) = {
|
|
|
|
IsFeedEnabled = rss.IsFeedEnabled
|
|
|
|
FeedName = rss.FeedName
|
|
|
|
ItemsInFeed = defaultArg rss.ItemsInFeed 0
|
|
|
|
IsCategoryEnabled = rss.IsCategoryEnabled
|
|
|
|
IsTagEnabled = rss.IsTagEnabled
|
|
|
|
Copyright = defaultArg rss.Copyright ""
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2022-07-21 03:13:16 +00:00
|
|
|
/// Update RSS options from values in this model
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.UpdateOptions (rss: RssOptions) =
|
2022-06-23 00:35:12 +00:00
|
|
|
{ rss with
|
2022-07-19 00:05:10 +00:00
|
|
|
IsFeedEnabled = this.IsFeedEnabled
|
|
|
|
FeedName = this.FeedName
|
|
|
|
ItemsInFeed = if this.ItemsInFeed = 0 then None else Some this.ItemsInFeed
|
|
|
|
IsCategoryEnabled = this.IsCategoryEnabled
|
|
|
|
IsTagEnabled = this.IsTagEnabled
|
2023-12-16 22:59:33 +00:00
|
|
|
Copyright = noneIfBlank this.Copyright }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// View model to edit a tag mapping
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type EditTagMapModel = {
|
|
|
|
/// The ID of the tag mapping being edited
|
|
|
|
Id: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 22:59:33 +00:00
|
|
|
/// The tag being mapped to a different link value
|
|
|
|
Tag: string
|
|
|
|
|
|
|
|
/// The link value for the tag
|
|
|
|
UrlValue: string
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create an edit model from the tag mapping
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromMapping (tagMap: TagMap) : EditTagMapModel = {
|
|
|
|
Id = string tagMap.Id
|
|
|
|
Tag = tagMap.Tag
|
|
|
|
UrlValue = tagMap.UrlValue
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Whether this is a new tag mapping
|
|
|
|
member this.IsNew =
|
|
|
|
this.Id = "new"
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
2022-07-21 03:13:16 +00:00
|
|
|
/// View model to display a user's information
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 17:24:45 +00:00
|
|
|
type EditUserModel = {
|
|
|
|
/// The ID of the user
|
|
|
|
Id: string
|
2022-07-21 03:13:16 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The user's access level
|
|
|
|
AccessLevel: string
|
|
|
|
|
|
|
|
/// The user name (e-mail address)
|
|
|
|
Email: string
|
2022-07-21 03:13:16 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The URL of the user's personal site
|
|
|
|
Url: string
|
2022-07-21 03:13:16 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The user's first name
|
|
|
|
FirstName: string
|
2022-07-21 03:13:16 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The user's last name
|
|
|
|
LastName: string
|
2022-07-21 03:13:16 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The user's preferred name
|
|
|
|
PreferredName: string
|
|
|
|
|
|
|
|
/// The user's password
|
|
|
|
Password: string
|
|
|
|
|
|
|
|
/// Confirmation of the user's password
|
|
|
|
PasswordConfirm: string
|
|
|
|
} with
|
2022-07-21 03:13:16 +00:00
|
|
|
|
2023-12-16 22:59:33 +00:00
|
|
|
/// Construct a user edit form from a web log user
|
|
|
|
static member FromUser (user: WebLogUser) = {
|
|
|
|
Id = string user.Id
|
|
|
|
AccessLevel = string user.AccessLevel
|
|
|
|
Url = defaultArg user.Url ""
|
|
|
|
Email = user.Email
|
|
|
|
FirstName = user.FirstName
|
|
|
|
LastName = user.LastName
|
|
|
|
PreferredName = user.PreferredName
|
|
|
|
Password = ""
|
|
|
|
PasswordConfirm = ""
|
|
|
|
}
|
2022-07-21 03:13:16 +00:00
|
|
|
|
|
|
|
/// Is this a new user?
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.IsNew =
|
|
|
|
this.Id = "new"
|
2022-07-21 03:13:16 +00:00
|
|
|
|
|
|
|
/// Update a user with values from this model (excludes password)
|
2023-12-15 04:49:38 +00:00
|
|
|
member this.UpdateUser (user: WebLogUser) =
|
2022-07-21 03:13:16 +00:00
|
|
|
{ user with
|
2023-12-15 04:49:38 +00:00
|
|
|
AccessLevel = AccessLevel.Parse this.AccessLevel
|
2022-07-21 03:13:16 +00:00
|
|
|
Email = this.Email
|
|
|
|
Url = noneIfBlank this.Url
|
|
|
|
FirstName = this.FirstName
|
|
|
|
LastName = this.LastName
|
2023-12-16 22:59:33 +00:00
|
|
|
PreferredName = this.PreferredName }
|
2022-07-21 03:13:16 +00:00
|
|
|
|
|
|
|
|
2022-06-23 00:35:12 +00:00
|
|
|
/// The model to use to allow a user to log on
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type LogOnModel = {
|
|
|
|
/// The user's e-mail address
|
|
|
|
EmailAddress : string
|
|
|
|
|
|
|
|
/// The user's password
|
|
|
|
Password : string
|
|
|
|
|
|
|
|
/// Where the user should be redirected once they have logged on
|
|
|
|
ReturnTo : string option
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// An empty log on model
|
2023-12-16 22:59:33 +00:00
|
|
|
static member Empty =
|
2022-07-18 03:10:30 +00:00
|
|
|
{ EmailAddress = ""; Password = ""; ReturnTo = None }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// View model to manage permalinks
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 03:46:12 +00:00
|
|
|
type ManagePermalinksModel = {
|
|
|
|
/// The ID for the entity being edited
|
|
|
|
Id: string
|
|
|
|
|
|
|
|
/// The type of entity being edited ("page" or "post")
|
|
|
|
Entity: string
|
|
|
|
|
|
|
|
/// The current title of the page or post
|
|
|
|
CurrentTitle: string
|
|
|
|
|
|
|
|
/// The current permalink of the page or post
|
|
|
|
CurrentPermalink: string
|
|
|
|
|
|
|
|
/// The prior permalinks for the page or post
|
|
|
|
Prior: string array
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a permalink model from a page
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromPage (page: Page) = {
|
|
|
|
Id = string page.Id
|
|
|
|
Entity = "page"
|
|
|
|
CurrentTitle = page.Title
|
|
|
|
CurrentPermalink = string page.Permalink
|
|
|
|
Prior = page.PriorPermalinks |> List.map string |> Array.ofList
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a permalink model from a post
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromPost (post: Post) = {
|
|
|
|
Id = string post.Id
|
|
|
|
Entity = "post"
|
|
|
|
CurrentTitle = post.Title
|
|
|
|
CurrentPermalink = string post.Permalink
|
|
|
|
Prior = post.PriorPermalinks |> List.map string |> Array.ofList
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
2022-07-15 03:25:29 +00:00
|
|
|
/// View model to manage revisions
|
2022-07-18 03:10:30 +00:00
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type ManageRevisionsModel = {
|
|
|
|
/// The ID for the entity being edited
|
|
|
|
Id: string
|
|
|
|
|
|
|
|
/// The type of entity being edited ("page" or "post")
|
|
|
|
Entity: string
|
|
|
|
|
|
|
|
/// The current title of the page or post
|
|
|
|
CurrentTitle: string
|
|
|
|
|
|
|
|
/// The revisions for the page or post
|
|
|
|
Revisions: DisplayRevision array
|
|
|
|
} with
|
2022-07-15 03:25:29 +00:00
|
|
|
|
|
|
|
/// Create a revision model from a page
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromPage webLog (page: Page) = {
|
|
|
|
Id = string page.Id
|
|
|
|
Entity = "page"
|
|
|
|
CurrentTitle = page.Title
|
|
|
|
Revisions = page.Revisions |> List.map (DisplayRevision.FromRevision webLog) |> Array.ofList
|
|
|
|
}
|
2022-07-15 03:25:29 +00:00
|
|
|
|
|
|
|
/// Create a revision model from a post
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromPost webLog (post: Post) = {
|
|
|
|
Id = string post.Id
|
|
|
|
Entity = "post"
|
|
|
|
CurrentTitle = post.Title
|
|
|
|
Revisions = post.Revisions |> List.map (DisplayRevision.FromRevision webLog) |> Array.ofList
|
|
|
|
}
|
2022-07-15 03:25:29 +00:00
|
|
|
|
|
|
|
|
2022-06-23 00:35:12 +00:00
|
|
|
/// View model for posts in a list
|
|
|
|
[<NoComparison; NoEquality>]
|
2023-12-16 03:46:12 +00:00
|
|
|
type PostListItem = {
|
|
|
|
/// The ID of the post
|
|
|
|
Id: string
|
|
|
|
|
|
|
|
/// The ID of the user who authored the post
|
|
|
|
AuthorId: string
|
|
|
|
|
|
|
|
/// The status of the post
|
|
|
|
Status: string
|
|
|
|
|
|
|
|
/// The title of the post
|
|
|
|
Title: string
|
|
|
|
|
|
|
|
/// The permalink for the post
|
|
|
|
Permalink: string
|
|
|
|
|
|
|
|
/// When this post was published
|
|
|
|
PublishedOn: Nullable<DateTime>
|
|
|
|
|
|
|
|
/// When this post was last updated
|
|
|
|
UpdatedOn: DateTime
|
|
|
|
|
|
|
|
/// The text of the post
|
|
|
|
Text: string
|
|
|
|
|
|
|
|
/// The IDs of the categories for this post
|
|
|
|
CategoryIds: string list
|
|
|
|
|
|
|
|
/// Tags for the post
|
|
|
|
Tags: string list
|
|
|
|
|
|
|
|
/// The podcast episode information for this post
|
|
|
|
Episode: Episode option
|
|
|
|
|
|
|
|
/// Metadata for the post
|
|
|
|
Metadata: MetaItem list
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a post list item from a post
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromPost (webLog: WebLog) (post: Post) = {
|
2023-12-16 19:05:45 +00:00
|
|
|
Id = string post.Id
|
|
|
|
AuthorId = string post.AuthorId
|
|
|
|
Status = string post.Status
|
|
|
|
Title = post.Title
|
|
|
|
Permalink = string post.Permalink
|
|
|
|
PublishedOn = post.PublishedOn |> Option.map webLog.LocalTime |> Option.toNullable
|
|
|
|
UpdatedOn = webLog.LocalTime post.UpdatedOn
|
|
|
|
Text = addBaseToRelativeUrls webLog.ExtraPath post.Text
|
|
|
|
CategoryIds = post.CategoryIds |> List.map string
|
|
|
|
Tags = post.Tags
|
|
|
|
Episode = post.Episode
|
|
|
|
Metadata = post.Metadata
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// View model for displaying posts
|
2023-12-16 22:59:33 +00:00
|
|
|
type PostDisplay = {
|
|
|
|
/// The posts to be displayed
|
|
|
|
Posts: PostListItem array
|
|
|
|
|
|
|
|
/// Author ID -> name lookup
|
|
|
|
Authors: MetaItem list
|
|
|
|
|
|
|
|
/// A subtitle for the page
|
|
|
|
Subtitle: string option
|
|
|
|
|
|
|
|
/// The link to view newer (more recent) posts
|
|
|
|
NewerLink: string option
|
|
|
|
|
|
|
|
/// The name of the next newer post (single-post only)
|
|
|
|
NewerName: string option
|
|
|
|
|
|
|
|
/// The link to view older (less recent) posts
|
|
|
|
OlderLink: string option
|
|
|
|
|
|
|
|
/// The name of the next older post (single-post only)
|
|
|
|
OlderName: string option
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// View model for editing web log settings
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 17:24:45 +00:00
|
|
|
type SettingsModel = {
|
|
|
|
/// The name of the web log
|
|
|
|
Name: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The slug of the web log
|
|
|
|
Slug: string
|
|
|
|
|
|
|
|
/// The subtitle of the web log
|
|
|
|
Subtitle: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The default page
|
|
|
|
DefaultPage: string
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// How many posts should appear on index pages
|
|
|
|
PostsPerPage: int
|
2022-06-23 00:35:12 +00:00
|
|
|
|
2023-12-16 17:24:45 +00:00
|
|
|
/// The time zone in which dates/times should be displayed
|
|
|
|
TimeZone: string
|
|
|
|
|
|
|
|
/// The theme to use to display the web log
|
|
|
|
ThemeId: string
|
|
|
|
|
|
|
|
/// Whether to automatically load htmx
|
|
|
|
AutoHtmx: bool
|
|
|
|
|
|
|
|
/// The default location for uploads
|
|
|
|
Uploads: string
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Create a settings model from a web log
|
2023-12-16 22:59:33 +00:00
|
|
|
static member FromWebLog(webLog: WebLog) = {
|
|
|
|
Name = webLog.Name
|
|
|
|
Slug = webLog.Slug
|
|
|
|
Subtitle = defaultArg webLog.Subtitle ""
|
|
|
|
DefaultPage = webLog.DefaultPage
|
|
|
|
PostsPerPage = webLog.PostsPerPage
|
|
|
|
TimeZone = webLog.TimeZone
|
|
|
|
ThemeId = string webLog.ThemeId
|
|
|
|
AutoHtmx = webLog.AutoHtmx
|
|
|
|
Uploads = string webLog.Uploads
|
|
|
|
}
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// Update a web log with settings from the form
|
2023-12-16 22:59:33 +00:00
|
|
|
member this.Update(webLog: WebLog) =
|
2022-06-23 00:35:12 +00:00
|
|
|
{ webLog with
|
2022-07-19 00:05:10 +00:00
|
|
|
Name = this.Name
|
|
|
|
Slug = this.Slug
|
|
|
|
Subtitle = if this.Subtitle = "" then None else Some this.Subtitle
|
|
|
|
DefaultPage = this.DefaultPage
|
|
|
|
PostsPerPage = this.PostsPerPage
|
|
|
|
TimeZone = this.TimeZone
|
|
|
|
ThemeId = ThemeId this.ThemeId
|
|
|
|
AutoHtmx = this.AutoHtmx
|
2023-12-16 22:59:33 +00:00
|
|
|
Uploads = UploadDestination.Parse this.Uploads }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
|
2022-07-02 00:59:21 +00:00
|
|
|
/// View model for uploading a file
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type UploadFileModel = {
|
|
|
|
/// The upload destination
|
|
|
|
Destination : string
|
|
|
|
}
|
2022-07-02 00:59:21 +00:00
|
|
|
|
|
|
|
|
2022-07-24 20:32:37 +00:00
|
|
|
/// View model for uploading a theme
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type UploadThemeModel = {
|
|
|
|
/// Whether the uploaded theme should overwrite an existing theme
|
|
|
|
DoOverwrite : bool
|
|
|
|
}
|
2022-07-24 20:32:37 +00:00
|
|
|
|
|
|
|
|
2022-07-02 00:59:21 +00:00
|
|
|
/// A message displayed to the user
|
2022-06-23 00:35:12 +00:00
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
2023-12-16 22:59:33 +00:00
|
|
|
type UserMessage = {
|
|
|
|
/// The level of the message
|
|
|
|
Level: string
|
|
|
|
|
|
|
|
/// The message
|
|
|
|
Message: string
|
|
|
|
|
|
|
|
/// Further details about the message
|
|
|
|
Detail: string option
|
|
|
|
} with
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// An empty user message (use one of the others for pre-filled level)
|
2023-12-16 22:59:33 +00:00
|
|
|
static member Empty = { Level = ""; Message = ""; Detail = None }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// A blank success message
|
2023-12-16 22:59:33 +00:00
|
|
|
static member Success = { UserMessage.Empty with Level = "success" }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// A blank informational message
|
2023-12-16 22:59:33 +00:00
|
|
|
static member Info = { UserMessage.Empty with Level = "primary" }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// A blank warning message
|
2023-12-16 22:59:33 +00:00
|
|
|
static member Warning = { UserMessage.Empty with Level = "warning" }
|
2022-06-23 00:35:12 +00:00
|
|
|
|
|
|
|
/// A blank error message
|
2023-12-16 22:59:33 +00:00
|
|
|
static member Error = { UserMessage.Empty with Level = "danger" }
|