mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
refactor: Created Open_Graph struct for og data.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
- [ ] Content-hash fingerprinting for CSS and JS cache busting
|
- [ ] Content-hash fingerprinting for CSS and JS cache busting
|
||||||
- [ ] Clean up the default layouts
|
- [ ] Clean up the default layouts
|
||||||
|
- [ ] Memory
|
||||||
|
- [ ] Not sure whether to use temp allocator or site_allocator in opengraph.odin.
|
||||||
- [ ] Performance
|
- [ ] Performance
|
||||||
- [ ] See if we can disable bounds checks in `write_indented` and elsewhere.
|
- [ ] See if we can disable bounds checks in `write_indented` and elsewhere.
|
||||||
- [ ] Instead of loading the site fresh each time in watch mode, create a
|
- [ ] Instead of loading the site fresh each time in watch mode, create a
|
||||||
|
|||||||
+5
-5
@@ -7,18 +7,16 @@ Open_Graph :: struct {
|
|||||||
type: string,
|
type: string,
|
||||||
image: string,
|
image: string,
|
||||||
url: string,
|
url: string,
|
||||||
|
|
||||||
description: string,
|
description: string,
|
||||||
locale: string,
|
locale: string,
|
||||||
site_name: string,
|
site_name: string,
|
||||||
|
|
||||||
is_article: bool,
|
is_article: bool,
|
||||||
published_time: string,
|
published_time: string,
|
||||||
modified_time: string,
|
modified_time: string,
|
||||||
section: string,
|
section: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
og_init :: proc(site: ^Site) -> Open_Graph {
|
og_init :: proc(site: Site) -> Open_Graph {
|
||||||
return {
|
return {
|
||||||
site_name = site.title,
|
site_name = site.title,
|
||||||
description = site.description,
|
description = site.description,
|
||||||
@@ -27,14 +25,16 @@ og_init :: proc(site: ^Site) -> Open_Graph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
og_for_page :: proc(site: ^Site, page: Page, base: Open_Graph) -> Open_Graph {
|
og_for_page :: proc(site: Site, page: Page, base: Open_Graph) -> Open_Graph {
|
||||||
og := base
|
og := base
|
||||||
is_article := page.section != ""
|
is_article := page.section != ""
|
||||||
og.url = fmt.tprintf("%s%s", site.base_url, page.permalink)
|
og.url = fmt.tprintf("%s%s", site.base_url, page.permalink)
|
||||||
og.title = strip_html_tags(page.title)
|
og.title = strip_html_tags(page.title, context.temp_allocator)
|
||||||
og.type = "article" if is_article else "website"
|
og.type = "article" if is_article else "website"
|
||||||
og.is_article = is_article
|
og.is_article = is_article
|
||||||
og.section = page.section
|
og.section = page.section
|
||||||
og.published_time = page.date
|
og.published_time = page.date
|
||||||
|
|
||||||
return og
|
return og
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-14
@@ -60,8 +60,8 @@ build_page_context :: proc(page: Page) -> Page_Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strip_html_tags :: proc(s: string) -> string {
|
strip_html_tags :: proc(s: string, allocator := context.allocator) -> string {
|
||||||
sb := strings.builder_make()
|
sb := strings.builder_make(allocator)
|
||||||
defer strings.builder_destroy(&sb)
|
defer strings.builder_destroy(&sb)
|
||||||
|
|
||||||
in_tag := false
|
in_tag := false
|
||||||
@@ -179,12 +179,7 @@ render_site :: proc(site: ^Site) {
|
|||||||
now = now,
|
now = now,
|
||||||
author = site.author,
|
author = site.author,
|
||||||
params = site.params,
|
params = site.params,
|
||||||
og = {
|
og = og_init(site^),
|
||||||
site_name = site.title,
|
|
||||||
description = site.description,
|
|
||||||
image = fmt.tprintf("%s/avatar.jpg", site.base_url),
|
|
||||||
locale = "en_US",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find home page
|
// Find home page
|
||||||
@@ -297,12 +292,7 @@ render_page_html :: proc(
|
|||||||
data.body = page.body_html
|
data.body = page.body_html
|
||||||
data.date_iso = page.date
|
data.date_iso = page.date
|
||||||
data.date_display = format_date(page.date)
|
data.date_display = format_date(page.date)
|
||||||
data.og.url = fmt.tprintf("%s%s", site.base_url, page.permalink)
|
data.og = og_for_page(site^, page, base.og)
|
||||||
data.og.title = strip_html_tags(page.title)
|
|
||||||
data.og.type = "article" if is_article else "website"
|
|
||||||
data.og.is_article = is_article
|
|
||||||
data.og.section = page.section
|
|
||||||
data.og.published_time = page.date
|
|
||||||
return render_template(content_tpl, data, partials)
|
return render_template(content_tpl, data, partials)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user