mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: Added site to the template context stack.
This commit is contained in:
@@ -2,14 +2,18 @@
|
|||||||
|
|
||||||
- Polish existing features before moving on to new ones.
|
- Polish existing features before moving on to new ones.
|
||||||
- [ ] Improve diagnostics
|
- [ ] Improve diagnostics
|
||||||
- [ ] Simplify / unify template context stack. Come up with a name for it.
|
- [x] Simplify / unify template context stack. Come up with a name for it.
|
||||||
- [ ] `render_template` should accept `Template_Context`, not `any`
|
- [x] `render_template` should accept `Template_Context`, not `any`
|
||||||
- [ ] Load grammars dynamically
|
- [ ] Load grammars dynamically
|
||||||
- [ ] consider adding a limit to the context stack in mustache.
|
- [ ] consider adding a limit to the context stack in mustache.
|
||||||
- [ ] better diagnostics for syntax errors in treesitter.
|
- [ ] better diagnostics for syntax errors in treesitter.
|
||||||
- [x] Add heading ids as a default on extension.
|
- [x] Add heading ids as a default on extension.
|
||||||
- [ ] show "stack traces" in template error diagnostics
|
- [ ] show "stack traces" in template error diagnostics
|
||||||
- [ ] starred must be a param.
|
- [ ] starred must be a param.
|
||||||
|
- [ ] Add a `#config(MAX_CONTEXT_DEPTH, 16?)` to `mustache`.
|
||||||
|
- [ ] menu system
|
||||||
|
- [ ] like Hugo's, but warn(/fail?) if menus are defined in the config *and* pages.
|
||||||
|
- i.e. force the user to choose one or the other.
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
|
|
||||||
|
|||||||
+4
-14
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import "mustache"
|
import "mustache"
|
||||||
|
|
||||||
import "core:encoding/json"
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:log"
|
import "core:log"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
@@ -11,13 +10,12 @@ import "core:time"
|
|||||||
import "core:time/datetime"
|
import "core:time/datetime"
|
||||||
|
|
||||||
Template_Context :: struct {
|
Template_Context :: struct {
|
||||||
params: json.Value,
|
|
||||||
now: string,
|
now: string,
|
||||||
title: string,
|
title: string,
|
||||||
description: string,
|
|
||||||
og: Open_Graph,
|
|
||||||
date_format: string,
|
date_format: string,
|
||||||
timezone: ^datetime.TZ_Region,
|
timezone: ^datetime.TZ_Region,
|
||||||
|
og: Open_Graph,
|
||||||
|
site: Site_Context,
|
||||||
page: Page,
|
page: Page,
|
||||||
|
|
||||||
// Home data
|
// Home data
|
||||||
@@ -106,14 +104,7 @@ render_template :: proc(
|
|||||||
ctx: Template_Context,
|
ctx: Template_Context,
|
||||||
partials: map[string]mustache.Template,
|
partials: map[string]mustache.Template,
|
||||||
) -> string {
|
) -> string {
|
||||||
result, err := mustache.render(
|
result, err := mustache.render(content_tpl, []any{ctx.site, ctx.page, ctx}, partials)
|
||||||
content_tpl,
|
|
||||||
[]any { /*ctx.site,*/
|
|
||||||
ctx.page,
|
|
||||||
ctx,
|
|
||||||
},
|
|
||||||
partials,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.errorf(
|
log.errorf(
|
||||||
"%s",
|
"%s",
|
||||||
@@ -142,9 +133,8 @@ render_site :: proc(site: ^Site) {
|
|||||||
assert(ok2)
|
assert(ok2)
|
||||||
|
|
||||||
ctx := Template_Context {
|
ctx := Template_Context {
|
||||||
|
site = site.site_context,
|
||||||
now = now,
|
now = now,
|
||||||
params = site.params,
|
|
||||||
description = site.description,
|
|
||||||
og = site.og,
|
og = site.og,
|
||||||
date_format = site.date.format,
|
date_format = site.date.format,
|
||||||
timezone = site.tz,
|
timezone = site.tz,
|
||||||
|
|||||||
@@ -13,24 +13,31 @@ import "core:time/timezone"
|
|||||||
import md "markdown"
|
import md "markdown"
|
||||||
|
|
||||||
|
|
||||||
// Site is the primary workhorse.
|
// Site_Context holds the site date that is accessible in templates.
|
||||||
|
Site_Context :: struct {
|
||||||
|
title: string,
|
||||||
|
description: string,
|
||||||
|
base_url: string,
|
||||||
|
params: json.Object,
|
||||||
|
og: Open_Graph,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Site is the primary workhorse, containing everything needed to build the site,
|
||||||
|
// including an arena allocator, the pages, and all the various directories and
|
||||||
|
// enabled features.
|
||||||
Site :: struct {
|
Site :: struct {
|
||||||
|
using site_context: Site_Context,
|
||||||
arena: mem.Dynamic_Arena,
|
arena: mem.Dynamic_Arena,
|
||||||
pages: #soa[dynamic]Page,
|
pages: #soa[dynamic]Page,
|
||||||
modules: [dynamic]string,
|
modules: [dynamic]string,
|
||||||
vfs: VFS,
|
vfs: VFS,
|
||||||
title: string,
|
|
||||||
description: string,
|
|
||||||
base_url: string,
|
|
||||||
config_path: string,
|
config_path: string,
|
||||||
content_dir: string,
|
content_dir: string,
|
||||||
assets_dir: string,
|
assets_dir: string,
|
||||||
output_dir: string,
|
output_dir: string,
|
||||||
layouts_dir: string,
|
layouts_dir: string,
|
||||||
params: json.Object,
|
|
||||||
features: bit_set[Feature],
|
features: bit_set[Feature],
|
||||||
markdown_extensions: bit_set[md.Extension],
|
markdown_extensions: bit_set[md.Extension],
|
||||||
og: Open_Graph,
|
|
||||||
date: Date_Preferences,
|
date: Date_Preferences,
|
||||||
tz: ^datetime.TZ_Region,
|
tz: ^datetime.TZ_Region,
|
||||||
grammars: string,
|
grammars: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user