55 lines
1.2 KiB
TypeScript
55 lines
1.2 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
import type { LayoutServerLoad } from './$types';
|
|
|
|
export const load: LayoutServerLoad = async ({ platform }) => {
|
|
const db = platform?.env?.DB;
|
|
|
|
const aliases = {
|
|
post: '文章',
|
|
page: '页面',
|
|
category: '分类',
|
|
tag: '标签',
|
|
series: '系列'
|
|
};
|
|
|
|
const site = {
|
|
title: 'BlogFlare',
|
|
description: 'A high-performance blog powered by Cloudflare D1, R2, and KV.',
|
|
avatar_enabled: 'true',
|
|
avatar_url: '',
|
|
launch_date: ''
|
|
};
|
|
|
|
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 (err: any) {
|
|
console.error('Failed to load settings', err);
|
|
}
|
|
}
|
|
|
|
return {
|
|
aliases,
|
|
site
|
|
};
|
|
};
|