updates for events

This commit is contained in:
2023-05-21 14:35:55 -07:00
parent 17a406e546
commit 2dd300f4dc
8 changed files with 81 additions and 66 deletions

View File

@@ -10,6 +10,7 @@ import { render_markdown_to_html, render_markdown_to_html_inline_sync } from '@d
import { RSSEntry } from './rss';
import { DateTime } from 'luxon';
import { EventEntry } from './icalendar';
import { as_context_time, as_html_time, from_iso } from '../time';
export interface OutFileURL {
base_url: string;
@@ -82,6 +83,22 @@ export async function build_partials(state: BuildState) {
}
export function mustache_context(state: BuildState, page_url: string, frontmatter?: FrontMatter) : Context {
let event: Context['event'] = {
start: null,
end: null,
zone: null,
};
if (frontmatter?.event) {
const start = from_iso(frontmatter.event.start, frontmatter.event.zone);
event.start = as_context_time(start);
const end = from_iso(frontmatter.event.end, frontmatter.event.zone);
event.end = as_context_time(end);
event.zone = frontmatter.event.zone;
}
return {
env: state.env,
page: frontmatter,
@@ -89,6 +106,7 @@ export function mustache_context(state: BuildState, page_url: string, frontmatte
page_url: page_url,
site_title: state.conf.title,
author: get_author(state, frontmatter),
event: event,
build_time: state.build_time,
icons: icons,
rss_feeds: state.conf.rss || [ ],
@@ -173,8 +191,12 @@ function handle_page_side_effects(state: BuildState, in_file: string, out_file:
}
function handle_rss(state: BuildState, rss_conf: RSSConfig, entries: RSSEntry[], in_file: string, out_url: OutFileURL, text: string, frontmatter: FrontMatter) {
if (frontmatter?.rss?.skip) {
return;
}
const author_or_authors = get_author(state, frontmatter);
const author = Array.isArray(author_or_authors) ? author_or_authors[0] : author_or_authors;
const authors = author_or_authors && (Array.isArray(author_or_authors) ? author_or_authors : [ author_or_authors ]);
entries.push({
url: out_url.abs_url,
@@ -182,12 +204,16 @@ function handle_rss(state: BuildState, rss_conf: RSSConfig, entries: RSSEntry[],
html_content: text,
title: frontmatter?.title,
description: frontmatter?.description,
author_name: author?.name,
authors: authors,
tags: frontmatter?.tags,
});
}
function handle_sitemap(state: BuildState, out_url: OutFileURL, frontmatter: FrontMatter) {
if (frontmatter?.sitemap?.skip) {
return;
}
state.sitemap.push({
url: out_url.abs_url,
lastmod: state.build_time.iso,
@@ -211,9 +237,9 @@ function handle_event(state: BuildState, in_file: string, out_url: OutFileURL, f
description: frontmatter.description,
author_name: author?.name,
author_email: author?.email,
start_time: frontmatter.event?.start_time,
end_time: frontmatter.event?.end_time,
time_zone: frontmatter.event?.time_zone,
start_time: frontmatter.event?.start,
end_time: frontmatter.event?.end,
time_zone: frontmatter.event?.zone,
});
}
@@ -228,9 +254,9 @@ function handle_calendar(state: BuildState, cal_conf: CalendarConfig, entries: E
description: frontmatter.description,
author_name: author?.name,
author_email: author?.email,
start_time: frontmatter.event?.start_time,
end_time: frontmatter.event?.end_time,
time_zone: frontmatter.event?.time_zone,
start_time: frontmatter.event?.start,
end_time: frontmatter.event?.end,
time_zone: frontmatter.event?.zone,
});
}