51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import type { LayoutServerLoad } from './$types';
|
|
|
|
export const load: LayoutServerLoad = async ({ platform }) => {
|
|
const db = platform?.env?.DB;
|
|
|
|
let aliases = {
|
|
post: '文章',
|
|
page: '页面',
|
|
category: '分类',
|
|
tag: '标签'
|
|
};
|
|
|
|
let site = {
|
|
title: 'BlogFlare',
|
|
description: 'A high-performance blog powered by Cloudflare D1, R2, and KV.',
|
|
avatar_enabled: 'true',
|
|
avatar_url: ''
|
|
};
|
|
|
|
if (db) {
|
|
try {
|
|
const { results } = await db.prepare(
|
|
"SELECT key, value FROM settings WHERE key LIKE 'alias.%' OR key LIKE 'site.%'"
|
|
).all();
|
|
|
|
if (results && results.length > 0) {
|
|
results.forEach((row: any) => {
|
|
if (row.key.startsWith('alias.')) {
|
|
const type = row.key.split('.')[1];
|
|
if (type && type in aliases) {
|
|
(aliases as any)[type] = row.value;
|
|
}
|
|
} else if (row.key.startsWith('site.')) {
|
|
const type = row.key.split('.')[1];
|
|
if (type && type in site) {
|
|
(site as any)[type] = row.value;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.error('Failed to load settings', e);
|
|
}
|
|
}
|
|
|
|
return {
|
|
aliases,
|
|
site
|
|
};
|
|
};
|