Fix page/post template lists

- WIP on loading themes from different directory
This commit is contained in:
2022-06-08 00:02:51 -04:00
parent 890fc6e60e
commit 07a2c404d7
4 changed files with 31 additions and 16 deletions

View File

@@ -163,7 +163,8 @@ let editPage pgId : HttpHandler = fun next ctx -> task {
}
match result with
| Some (title, page) ->
let model = EditPageModel.fromPage page
let model = EditPageModel.fromPage page
let! templates = templatesForTheme ctx "page"
return!
Hash.FromAnonymousObject {|
csrf = csrfToken ctx
@@ -171,7 +172,7 @@ let editPage pgId : HttpHandler = fun next ctx -> task {
metadata = Array.zip model.metaNames model.metaValues
|> Array.mapi (fun idx (name, value) -> [| string idx; name; value |])
page_title = title
templates = templatesForTheme ctx "page"
templates = templates
|}
|> viewForTheme "admin" "page-edit" next ctx
| None -> return! Error.notFound next ctx

View File

@@ -185,19 +185,20 @@ open System.Collections.Generic
open System.IO
/// Get the templates available for the current web log's theme (in a key/value pair list)
let templatesForTheme (ctx : HttpContext) (typ : string) =
seq {
KeyValuePair.Create ("", $"- Default (single-{typ}) -")
yield!
Path.Combine ("themes", ctx.WebLog.themePath)
|> Directory.EnumerateFiles
|> Seq.filter (fun it -> it.EndsWith $"{typ}.liquid")
|> Seq.map (fun it ->
let parts = it.Split Path.DirectorySeparatorChar
let template = parts[parts.Length - 1].Replace (".liquid", "")
KeyValuePair.Create (template, template))
}
|> Array.ofSeq
let templatesForTheme (ctx : HttpContext) (typ : string) = backgroundTask {
match! Data.Theme.findByIdWithoutText (ThemeId ctx.WebLog.themePath) ctx.Conn with
| Some theme ->
return seq {
KeyValuePair.Create ("", $"- Default (single-{typ}) -")
yield!
theme.templates
|> Seq.ofList
|> Seq.filter (fun it -> it.name.EndsWith $"-{typ}" && it.name <> $"single-{typ}")
|> Seq.map (fun it -> KeyValuePair.Create (it.name, it.name))
}
|> Array.ofSeq
| None -> return [| KeyValuePair.Create ("", $"- Default (single-{typ}) -") |]
}
/// Get all authors for a list of posts as metadata items
let getAuthors (webLog : WebLog) (posts : Post list) conn =