mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
refactor(Page): Renamed body_html to content.
This commit is contained in:
+32
-18
@@ -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(
|
||||||
path = strings.clone(entry.fullpath, context.temp_allocator),
|
pending,
|
||||||
section = section,
|
Pending_File {
|
||||||
slug = slug,
|
path = strings.clone(entry.fullpath, context.temp_allocator),
|
||||||
is_index = is_idx,
|
section = section,
|
||||||
})
|
slug = slug,
|
||||||
|
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(
|
||||||
path = strings.clone(index_path, context.temp_allocator),
|
pending,
|
||||||
section = section,
|
Pending_File {
|
||||||
slug = entry.name,
|
path = strings.clone(index_path, context.temp_allocator),
|
||||||
is_index = false,
|
section = section,
|
||||||
})
|
slug = entry.name,
|
||||||
|
is_index = false,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .Undetermined, .Symlink, .Named_Pipe, .Socket, .Block_Device, .Character_Device:
|
case .Undetermined, .Symlink, .Named_Pipe, .Socket, .Block_Device, .Character_Device:
|
||||||
@@ -140,8 +152,9 @@ 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) &&
|
||||||
(i + 3 <= len(line) && line[i] == '~' && line[i+1] == '~' && line[i+2] == '~') {
|
(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
|
||||||
for j < len(line) && line[j] == fence_char {
|
for j < len(line) && line[j] == fence_char {
|
||||||
@@ -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]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -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
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user