feat: first commit
This commit is contained in:
commit
74386d26a2
39 files changed
+6005
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import { parseEventSource } from '../src/data/event-parser';
|
||||
import { validateEventCollection } from '../src/data/event-schema';
|
||||
|
||||
const eventDirectory = resolve(process.cwd(), 'src/content/events');
|
||||
const publicDirectory = resolve(process.cwd(), 'public');
|
||||
const eventFiles = readdirSync(eventDirectory).filter((file) => file.endsWith('.md')).sort();
|
||||
|
||||
if (eventFiles.length === 0) {
|
||||
throw new Error(`No event Markdown files found in ${eventDirectory}`);
|
||||
}
|
||||
|
||||
const events = eventFiles.map((file) => {
|
||||
const filePath = resolve(eventDirectory, file);
|
||||
const event = parseEventSource(readFileSync(filePath, 'utf8'), file);
|
||||
const posterPath = resolve(publicDirectory, `.${event.poster}`);
|
||||
|
||||
if (!posterPath.startsWith(`${publicDirectory}/`) || !existsSync(posterPath)) {
|
||||
throw new Error(`${file}: poster does not exist in public/: ${event.poster}`);
|
||||
}
|
||||
|
||||
return event;
|
||||
});
|
||||
|
||||
validateEventCollection(events);
|
||||
console.log(`Validated ${events.length} event file${events.length === 1 ? '' : 's'}.`);
|
||||
Reference in new issue
Block a user