Add the CLI, site, and sample content so the project can run locally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { dirname, resolve } from 'node:path';
|
|
import YAML from 'yaml';
|
|
|
|
const siteRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../../..');
|
|
|
|
type SiteConfig = {
|
|
site: {
|
|
title: string;
|
|
description: string;
|
|
base_url: string;
|
|
language: string;
|
|
timezone: string;
|
|
};
|
|
content: {
|
|
posts_dir: string;
|
|
assets_dir: string;
|
|
};
|
|
build: {
|
|
astro_project: string;
|
|
output_dir: string;
|
|
};
|
|
};
|
|
|
|
const defaults: SiteConfig = {
|
|
site: {
|
|
title: 'Osaet',
|
|
description: 'Personal blog',
|
|
base_url: 'http://localhost:4321',
|
|
language: 'zh-CN',
|
|
timezone: 'Asia/Shanghai'
|
|
},
|
|
content: {
|
|
posts_dir: 'content/posts',
|
|
assets_dir: 'content/assets'
|
|
},
|
|
build: {
|
|
astro_project: 'frontend/site',
|
|
output_dir: 'dist/site'
|
|
}
|
|
};
|
|
|
|
function loadSiteConfig(): SiteConfig {
|
|
try {
|
|
const file = readFileSync(resolve(siteRoot, 'config/site.yaml'), 'utf8');
|
|
const parsed = YAML.parse(file) ?? {};
|
|
|
|
return {
|
|
site: { ...defaults.site, ...parsed.site },
|
|
content: { ...defaults.content, ...parsed.content },
|
|
build: { ...defaults.build, ...parsed.build }
|
|
};
|
|
} catch {
|
|
return defaults;
|
|
}
|
|
}
|
|
|
|
export const siteConfig = loadSiteConfig();
|
|
export const site = siteConfig.site;
|