feat: more work on calendar
This commit is contained in:
@@ -28,6 +28,8 @@ import {
|
||||
loadPublishedSnapshots,
|
||||
loadPublishedSnapshotsPage,
|
||||
} from './SharedSnapshotService';
|
||||
import { buildCalendarArchiveData } from './GenerationSitemapFeedService';
|
||||
import { loadPublishedGenerationSets } from './GenerationPostSnapshotService';
|
||||
|
||||
interface ActiveProjectContext {
|
||||
projectId: string;
|
||||
@@ -254,6 +256,12 @@ export class PreviewServer {
|
||||
const picoStylesheetHref = getPicoStylesheetHref(appliedTheme);
|
||||
const htmlRewriteContext = await this.buildHtmlRewriteContext();
|
||||
|
||||
if (pathname === '/calendar.json') {
|
||||
const calendarJson = await this.resolveCalendarJson(context.dataDir, listExcludedCategories);
|
||||
this.respondAsset(res, 'application/json; charset=utf-8', calendarJson);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathname === '/__style-preview') {
|
||||
const stylePreviewHtml = await this.renderStylePreview(htmlRewriteContext, {
|
||||
pageTitle,
|
||||
@@ -491,6 +499,21 @@ export class PreviewServer {
|
||||
}
|
||||
}
|
||||
|
||||
private async resolveCalendarJson(dataDir: string | undefined, listExcludedCategories: string[]): Promise<Buffer> {
|
||||
if (dataDir) {
|
||||
const calendarPath = path.join(dataDir, 'html', 'calendar.json');
|
||||
try {
|
||||
return await readFile(calendarPath);
|
||||
} catch {
|
||||
// fall through to dynamic generation for preview runtime
|
||||
}
|
||||
}
|
||||
|
||||
const { publishedListPosts } = await loadPublishedGenerationSets(this.postEngine, listExcludedCategories);
|
||||
const calendarJson = `${JSON.stringify(buildCalendarArchiveData(publishedListPosts), null, 2)}\n`;
|
||||
return Buffer.from(calendarJson, 'utf-8');
|
||||
}
|
||||
|
||||
private getMediaContentType(filePath: string): string {
|
||||
const extension = path.extname(filePath).toLowerCase();
|
||||
switch (extension) {
|
||||
|
||||
Reference in New Issue
Block a user