refactor(Page): Renamed body_html to content.

This commit is contained in:
Spencer Brower
2026-07-28 11:40:04 -04:00
parent 01d13ff279
commit e742832a4b
4 changed files with 40 additions and 28 deletions
+23 -9
View File
@@ -20,7 +20,7 @@ Page :: struct {
date: string, date: string,
lastmod: string, lastmod: string,
menu: string, menu: string,
body_html: string, content: string,
og: Open_Graph, og: Open_Graph,
draft: bool, draft: bool,
is_starred: bool, is_starred: bool,
@@ -52,7 +52,13 @@ site_load_content :: proc(site: ^Site) {
// Phase 3: Load pages (grammars already cached) // Phase 3: Load pages (grammars already cached)
for file in pending { for file in pending {
page, ok := load_page(file.path, file.section, file.slug, file.is_index, site.markdown_extensions) page, ok := load_page(
file.path,
file.section,
file.slug,
file.is_index,
site.markdown_extensions,
)
if ok && (!page.draft || .Drafts in site.features) { if ok && (!page.draft || .Drafts in site.features) {
append(&site.pages, page) append(&site.pages, page)
} }
@@ -85,12 +91,15 @@ scan_content_files :: proc(dir: string, section: string, pending: ^[dynamic]Pend
is_idx := filename == "index" is_idx := filename == "index"
slug := is_idx ? "" : filename slug := is_idx ? "" : filename
append(pending, Pending_File { append(
pending,
Pending_File {
path = strings.clone(entry.fullpath, context.temp_allocator), path = strings.clone(entry.fullpath, context.temp_allocator),
section = section, section = section,
slug = slug, slug = slug,
is_index = is_idx, is_index = is_idx,
}) },
)
case .Directory: case .Directory:
if section == "" { if section == "" {
@@ -101,12 +110,15 @@ scan_content_files :: proc(dir: string, section: string, pending: ^[dynamic]Pend
index_path = fmt.tprintf("%s/index.md", entry.fullpath) index_path = fmt.tprintf("%s/index.md", entry.fullpath)
} }
if os.exists(index_path) { if os.exists(index_path) {
append(pending, Pending_File { append(
pending,
Pending_File {
path = strings.clone(index_path, context.temp_allocator), path = strings.clone(index_path, context.temp_allocator),
section = section, section = section,
slug = entry.name, slug = entry.name,
is_index = false, is_index = false,
}) },
)
} }
} }
case .Undetermined, .Symlink, .Named_Pipe, .Socket, .Block_Device, .Character_Device: case .Undetermined, .Symlink, .Named_Pipe, .Socket, .Block_Device, .Character_Device:
@@ -140,7 +152,8 @@ collect_languages :: proc(files: []Pending_File) -> []string {
i += 1 i += 1
} }
if i + 3 <= len(line) && (line[i] == '`' && line[i+1] == '`' && line[i+2] == '`') || if i + 3 <= len(line) &&
(line[i] == '`' && line[i + 1] == '`' && line[i + 2] == '`') ||
(i + 3 <= len(line) && line[i] == '~' && line[i + 1] == '~' && line[i + 2] == '~') { (i + 3 <= len(line) && line[i] == '~' && line[i + 1] == '~' && line[i + 2] == '~') {
fence_char := line[i] fence_char := line[i]
j := i + 3 j := i + 3
@@ -226,9 +239,9 @@ load_page :: proc(
page.og = fm.og page.og = fm.og
if strings.has_suffix(file_path, ".html") { if strings.has_suffix(file_path, ".html") {
page.body_html = strings.clone(body) page.content = strings.clone(body)
} else { } else {
page.body_html = md.process(body, ext, file_path) page.content = md.process(body, ext, file_path)
} }
if section == "" && is_index { if section == "" && is_index {
@@ -256,3 +269,4 @@ strip_extension :: proc(name: string) -> string {
} }
return name[:dot] return name[:dot]
} }
+2 -5
View File
@@ -50,7 +50,7 @@ generate_rss :: proc(site: ^Site) -> string {
page.url, page.url,
pub_date, pub_date,
page.url, page.url,
xml_escape(page.body_html), xml_escape(page.content),
), ),
) )
} }
@@ -74,10 +74,7 @@ generate_sitemap :: proc(site: ^Site) -> string {
if page.date != "" { if page.date != "" {
lastmod = fmt.aprintf("<lastmod>%s</lastmod>", page.date) lastmod = fmt.aprintf("<lastmod>%s</lastmod>", page.date)
} }
strings.write_string( strings.write_string(&sb, fmt.aprintf("<url><loc>%s</loc>%s</url>\n", page.url, lastmod))
&sb,
fmt.aprintf("<url><loc>%s</loc>%s</url>\n", page.url, lastmod),
)
} }
// Section index pages (for sections without an index in content) // Section index pages (for sections without an index in content)
+3 -2
View File
@@ -70,8 +70,8 @@ og_for_page :: proc(site_og: Open_Graph, page: Page) -> Open_Graph {
og.description = page.description og.description = page.description
description_set = true description_set = true
} }
if !description_set && is_article && page.body_html != "" { if !description_set && is_article && page.content != "" {
og.description = generate_description(generate_summary(page.body_html)) og.description = generate_description(generate_summary(page.content))
description_set = true description_set = true
} }
if !description_set { if !description_set {
@@ -115,3 +115,4 @@ og_for_page :: proc(site_og: Open_Graph, page: Page) -> Open_Graph {
return og return og
} }
+3 -3
View File
@@ -269,7 +269,7 @@ render_page_html :: proc(
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_title = page.title ctx.page_title = page.title
ctx.content = page.body_html ctx.content = page.content
ctx.date = page.date ctx.date = page.date
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)
@@ -293,7 +293,7 @@ render_home_html :: proc(
ctx := ctx ctx := ctx
ctx.title = site.title ctx.title = site.title
ctx.content = home.body_html ctx.content = home.content
ctx.pages = list_pages ctx.pages = list_pages
ctx.og = og_for_page(site.og, home) ctx.og = og_for_page(site.og, home)
@@ -320,7 +320,7 @@ render_section :: proc(
ctx := ctx ctx := ctx
if has_index { if has_index {
ctx.content = section_index.body_html ctx.content = section_index.content
ctx.page_title = section_index.title ctx.page_title = section_index.title
ctx.title = fmt.tprintf("%s | %s", section_index.title, site.title) ctx.title = fmt.tprintf("%s | %s", section_index.title, site.title)
ctx.og = og_for_page(site.og, section_index) ctx.og = og_for_page(site.og, section_index)