mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: Errors are now tracked, so duplicate errors don't report more than once.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
- Polish existing features before moving on to new ones.
|
- Polish existing features before moving on to new ones.
|
||||||
- [ ] Improve diagnostics
|
- [ ] Improve diagnostics
|
||||||
- [ ] keep track of every error and don't report them more than once.
|
- [x] keep track of every error and don't report them more than once.
|
||||||
- [ ] All Diagnostics should show:
|
- [ ] All Diagnostics should show:
|
||||||
- [ ] *What* went wrong
|
- [ ] *What* went wrong
|
||||||
- [ ] *where* (in the file)
|
- [ ] *where* (in the file)
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
content template's source/path, which can point at the wrong file.
|
content template's source/path, which can point at the wrong file.
|
||||||
- [ ] try to make file paths clickable links.
|
- [ ] try to make file paths clickable links.
|
||||||
- [ ] centralize diagnostics to one place.
|
- [ ] centralize diagnostics to one place.
|
||||||
|
- [ ] consider logging the number of times an error occurred.
|
||||||
- [ ] Load grammars dynamically
|
- [ ] Load grammars dynamically
|
||||||
- [ ] starred must be a param.
|
- [ ] starred must be a param.
|
||||||
- [ ] Documentation
|
- [ ] Documentation
|
||||||
|
|||||||
+22
-8
@@ -121,13 +121,20 @@ render_template :: proc(
|
|||||||
content_tpl: mustache.Template,
|
content_tpl: mustache.Template,
|
||||||
ctx: Template_Context,
|
ctx: Template_Context,
|
||||||
partials: map[string]mustache.Template,
|
partials: map[string]mustache.Template,
|
||||||
|
reported_errors: ^map[string]bool,
|
||||||
) -> string {
|
) -> string {
|
||||||
result, err := mustache.render(content_tpl, []any{ctx.site, ctx.page, ctx}, partials)
|
result, err := mustache.render(content_tpl, []any{ctx.site, ctx.page, ctx}, partials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.errorf(
|
formatted := mustache.format_render_error(
|
||||||
"%s",
|
err,
|
||||||
mustache.format_render_error(err, content_tpl, colorize = mustache.should_colorize()),
|
content_tpl,
|
||||||
|
colorize = mustache.should_colorize(),
|
||||||
)
|
)
|
||||||
|
if formatted in reported_errors^ {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
reported_errors[formatted] = true
|
||||||
|
log.errorf("%s", formatted)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@@ -145,6 +152,8 @@ render_site :: proc(site: ^Site) {
|
|||||||
template_cache: map[string]mustache.Template
|
template_cache: map[string]mustache.Template
|
||||||
defer delete(template_cache)
|
defer delete(template_cache)
|
||||||
|
|
||||||
|
errors := make(map[string]bool, context.temp_allocator)
|
||||||
|
|
||||||
offset, ok := mustache.compute_utc_offset(site.tz)
|
offset, ok := mustache.compute_utc_offset(site.tz)
|
||||||
assert(ok)
|
assert(ok)
|
||||||
now, ok2 := time.time_to_rfc3339(time.now(), offset, false, allocator)
|
now, ok2 := time.time_to_rfc3339(time.now(), offset, false, allocator)
|
||||||
@@ -186,7 +195,7 @@ render_site :: proc(site: ^Site) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tpl := get_template(&site.vfs, page.layout, &template_cache)
|
tpl := get_template(&site.vfs, page.layout, &template_cache)
|
||||||
html := render_page_html(page, site, tpl, partials, ctx)
|
html := render_page_html(page, site, tpl, partials, ctx, &seen)
|
||||||
if .Minify in site.features {
|
if .Minify in site.features {
|
||||||
html = minify_html(html)
|
html = minify_html(html)
|
||||||
}
|
}
|
||||||
@@ -215,6 +224,7 @@ render_site :: proc(site: ^Site) {
|
|||||||
section_tpl,
|
section_tpl,
|
||||||
partials,
|
partials,
|
||||||
ctx,
|
ctx,
|
||||||
|
&seen,
|
||||||
)
|
)
|
||||||
if .Minify in site.features {
|
if .Minify in site.features {
|
||||||
html = minify_html(html)
|
html = minify_html(html)
|
||||||
@@ -225,7 +235,7 @@ render_site :: proc(site: ^Site) {
|
|||||||
// Render home page
|
// Render home page
|
||||||
if has_home {
|
if has_home {
|
||||||
home_tpl := get_template(&site.vfs, "home", &template_cache)
|
home_tpl := get_template(&site.vfs, "home", &template_cache)
|
||||||
home_html := render_home_html(home, site, home_tpl, partials, ctx)
|
home_html := render_home_html(home, site, home_tpl, partials, ctx, &seen)
|
||||||
if .Minify in site.features {
|
if .Minify in site.features {
|
||||||
home_html = minify_html(home_html)
|
home_html = minify_html(home_html)
|
||||||
}
|
}
|
||||||
@@ -260,12 +270,13 @@ render_page_html :: proc(
|
|||||||
content_tpl: mustache.Template,
|
content_tpl: mustache.Template,
|
||||||
partials: map[string]mustache.Template,
|
partials: map[string]mustache.Template,
|
||||||
ctx: Template_Context,
|
ctx: Template_Context,
|
||||||
|
seen: ^map[string]bool,
|
||||||
) -> string {
|
) -> string {
|
||||||
ctx := ctx
|
ctx := ctx
|
||||||
ctx.title = fmt.tprintf("%s | %s", page.title, site.title)
|
ctx.title = fmt.tprintf("%s | %s", page.title, site.title)
|
||||||
ctx.page = page
|
ctx.page = page
|
||||||
ctx.og = og_for_page(site.og, page)
|
ctx.og = og_for_page(site.og, page)
|
||||||
return render_template(content_tpl, ctx, partials)
|
return render_template(content_tpl, ctx, partials, seen)
|
||||||
}
|
}
|
||||||
|
|
||||||
render_home_html :: proc(
|
render_home_html :: proc(
|
||||||
@@ -274,6 +285,7 @@ render_home_html :: proc(
|
|||||||
content_tpl: mustache.Template,
|
content_tpl: mustache.Template,
|
||||||
partials: map[string]mustache.Template,
|
partials: map[string]mustache.Template,
|
||||||
ctx: Template_Context,
|
ctx: Template_Context,
|
||||||
|
seen: ^map[string]bool,
|
||||||
) -> string {
|
) -> string {
|
||||||
list_pages := make([dynamic]Page, 0, 8, context.temp_allocator)
|
list_pages := make([dynamic]Page, 0, 8, context.temp_allocator)
|
||||||
for page in site.pages {
|
for page in site.pages {
|
||||||
@@ -288,7 +300,7 @@ render_home_html :: proc(
|
|||||||
ctx.pages = list_pages
|
ctx.pages = list_pages
|
||||||
ctx.og = og_for_page(site.og, home)
|
ctx.og = og_for_page(site.og, home)
|
||||||
|
|
||||||
return render_template(content_tpl, ctx, partials)
|
return render_template(content_tpl, ctx, partials, seen)
|
||||||
}
|
}
|
||||||
|
|
||||||
render_section :: proc(
|
render_section :: proc(
|
||||||
@@ -299,6 +311,7 @@ render_section :: proc(
|
|||||||
content_tpl: mustache.Template,
|
content_tpl: mustache.Template,
|
||||||
partials: map[string]mustache.Template,
|
partials: map[string]mustache.Template,
|
||||||
ctx: Template_Context,
|
ctx: Template_Context,
|
||||||
|
seen: ^map[string]bool,
|
||||||
) -> string {
|
) -> string {
|
||||||
alloc := site_allocator(site)
|
alloc := site_allocator(site)
|
||||||
posts := make([dynamic]Page, 0, len(site.pages) / 2, context.temp_allocator)
|
posts := make([dynamic]Page, 0, len(site.pages) / 2, context.temp_allocator)
|
||||||
@@ -327,7 +340,7 @@ render_section :: proc(
|
|||||||
ctx.og.is_article = false
|
ctx.og.is_article = false
|
||||||
}
|
}
|
||||||
ctx.posts = posts
|
ctx.posts = posts
|
||||||
return render_template(content_tpl, ctx, partials)
|
return render_template(content_tpl, ctx, partials, seen)
|
||||||
}
|
}
|
||||||
|
|
||||||
load_partials :: proc(vfs: ^VFS) -> map[string]mustache.Template {
|
load_partials :: proc(vfs: ^VFS) -> map[string]mustache.Template {
|
||||||
@@ -417,3 +430,4 @@ write_file :: proc(path: string, html: string) {
|
|||||||
log.errorf("cannot write %s: %v", path, err)
|
log.errorf("cannot write %s: %v", path, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user