Fix page/post template lists
- WIP on loading themes from different directory
This commit is contained in:
parent
890fc6e60e
commit
07a2c404d7
|
@ -724,6 +724,15 @@ module Theme =
|
||||||
resultOption; withRetryOptionDefault
|
resultOption; withRetryOptionDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve a theme by its ID, excluding the text of templates
|
||||||
|
let findByIdWithoutText (themeId : ThemeId) =
|
||||||
|
rethink<Theme> {
|
||||||
|
withTable Table.Theme
|
||||||
|
get themeId
|
||||||
|
merge (fun row -> r.HashMap ("templates", row["templates"].Without [| "text" |]))
|
||||||
|
resultOption; withRetryOptionDefault
|
||||||
|
}
|
||||||
|
|
||||||
/// Save a theme
|
/// Save a theme
|
||||||
let save (theme : Theme) =
|
let save (theme : Theme) =
|
||||||
rethink {
|
rethink {
|
||||||
|
|
|
@ -164,6 +164,7 @@ let editPage pgId : HttpHandler = fun next ctx -> task {
|
||||||
match result with
|
match result with
|
||||||
| Some (title, page) ->
|
| Some (title, page) ->
|
||||||
let model = EditPageModel.fromPage page
|
let model = EditPageModel.fromPage page
|
||||||
|
let! templates = templatesForTheme ctx "page"
|
||||||
return!
|
return!
|
||||||
Hash.FromAnonymousObject {|
|
Hash.FromAnonymousObject {|
|
||||||
csrf = csrfToken ctx
|
csrf = csrfToken ctx
|
||||||
|
@ -171,7 +172,7 @@ let editPage pgId : HttpHandler = fun next ctx -> task {
|
||||||
metadata = Array.zip model.metaNames model.metaValues
|
metadata = Array.zip model.metaNames model.metaValues
|
||||||
|> Array.mapi (fun idx (name, value) -> [| string idx; name; value |])
|
|> Array.mapi (fun idx (name, value) -> [| string idx; name; value |])
|
||||||
page_title = title
|
page_title = title
|
||||||
templates = templatesForTheme ctx "page"
|
templates = templates
|
||||||
|}
|
|}
|
||||||
|> viewForTheme "admin" "page-edit" next ctx
|
|> viewForTheme "admin" "page-edit" next ctx
|
||||||
| None -> return! Error.notFound next ctx
|
| None -> return! Error.notFound next ctx
|
||||||
|
|
|
@ -185,19 +185,20 @@ open System.Collections.Generic
|
||||||
open System.IO
|
open System.IO
|
||||||
|
|
||||||
/// Get the templates available for the current web log's theme (in a key/value pair list)
|
/// Get the templates available for the current web log's theme (in a key/value pair list)
|
||||||
let templatesForTheme (ctx : HttpContext) (typ : string) =
|
let templatesForTheme (ctx : HttpContext) (typ : string) = backgroundTask {
|
||||||
seq {
|
match! Data.Theme.findByIdWithoutText (ThemeId ctx.WebLog.themePath) ctx.Conn with
|
||||||
|
| Some theme ->
|
||||||
|
return seq {
|
||||||
KeyValuePair.Create ("", $"- Default (single-{typ}) -")
|
KeyValuePair.Create ("", $"- Default (single-{typ}) -")
|
||||||
yield!
|
yield!
|
||||||
Path.Combine ("themes", ctx.WebLog.themePath)
|
theme.templates
|
||||||
|> Directory.EnumerateFiles
|
|> Seq.ofList
|
||||||
|> Seq.filter (fun it -> it.EndsWith $"{typ}.liquid")
|
|> Seq.filter (fun it -> it.name.EndsWith $"-{typ}" && it.name <> $"single-{typ}")
|
||||||
|> Seq.map (fun it ->
|
|> Seq.map (fun it -> KeyValuePair.Create (it.name, it.name))
|
||||||
let parts = it.Split Path.DirectorySeparatorChar
|
|
||||||
let template = parts[parts.Length - 1].Replace (".liquid", "")
|
|
||||||
KeyValuePair.Create (template, template))
|
|
||||||
}
|
}
|
||||||
|> Array.ofSeq
|
|> Array.ofSeq
|
||||||
|
| None -> return [| KeyValuePair.Create ("", $"- Default (single-{typ}) -") |]
|
||||||
|
}
|
||||||
|
|
||||||
/// Get all authors for a list of posts as metadata items
|
/// Get all authors for a list of posts as metadata items
|
||||||
let getAuthors (webLog : WebLog) (posts : Post list) conn =
|
let getAuthors (webLog : WebLog) (posts : Post list) conn =
|
||||||
|
|
|
@ -122,7 +122,11 @@ let importLinks args sp = task {
|
||||||
/// Load a theme from the given ZIP file
|
/// Load a theme from the given ZIP file
|
||||||
let loadTheme (args : string[]) (sp : IServiceProvider) = task {
|
let loadTheme (args : string[]) (sp : IServiceProvider) = task {
|
||||||
if args.Length > 1 then
|
if args.Length > 1 then
|
||||||
match Handlers.Admin.getThemeName args[1] with
|
let fileName =
|
||||||
|
match args[1].LastIndexOf Path.DirectorySeparatorChar with
|
||||||
|
| -1 -> args[1]
|
||||||
|
| it -> args[1][(it + 1)..]
|
||||||
|
match Handlers.Admin.getThemeName fileName with
|
||||||
| Some themeName ->
|
| Some themeName ->
|
||||||
let conn = sp.GetRequiredService<IConnection> ()
|
let conn = sp.GetRequiredService<IConnection> ()
|
||||||
let clean = if args.Length > 2 then bool.Parse args[2] else true
|
let clean = if args.Length > 2 then bool.Parse args[2] else true
|
||||||
|
|
Loading…
Reference in New Issue
Block a user