84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { error } from '@sveltejs/kit';
|
|
import type { PageServerLoad } from './$types';
|
|
import type { Content } from '$lib/article';
|
|
import PG from '$lib/server/database';
|
|
|
|
let data: {
|
|
recent: Content[],
|
|
tags: string[],
|
|
updated: string
|
|
} = {
|
|
recent: [
|
|
{
|
|
title: "title",
|
|
image: "image",
|
|
date: "date",
|
|
link: "link",
|
|
tags: ["tag1", "tag2"],
|
|
},
|
|
],
|
|
tags: ["hoge", "fuga", "piyo"],
|
|
updated: "",
|
|
};
|
|
|
|
export const load: PageServerLoad = async ({ params }) => {
|
|
const db = await PG();
|
|
const now = await db.query('SELECT NOW()');
|
|
await db.release();
|
|
|
|
data.updated = now.rows[0].now;
|
|
return data;
|
|
}
|
|
|
|
// export const load: PageServerLoad = async ({ params }) => {
|
|
// let data = {
|
|
// hero: [] as Content[],
|
|
// recent: [] as Content[],
|
|
// tags: Array.from(index.tags),
|
|
// updated: index.updated
|
|
// };
|
|
// for (const dat of index.articles.filter((article) => article.publish == "public").list.slice(0, 4).reverse()) {
|
|
// if (!dat) continue;
|
|
// data.hero.push({
|
|
// title: dat.title,
|
|
// image: dat.image,
|
|
// date: ((date) => {
|
|
// {
|
|
// // YYYY/MM/DD
|
|
// return `${date.getFullYear()}/${(date.getMonth() + 1).toString().padStart(2, '0')}/${date
|
|
// .getDate()
|
|
// .toString()
|
|
// .padStart(2, '0')}`;
|
|
// }
|
|
// })(dat.released),
|
|
// link: dat.series
|
|
// ? `/post/${dat.category}/${dat.series}/${dat.id}`
|
|
// : `/post/${dat.category}/${dat.id}`,
|
|
// tags: dat.tags
|
|
// });
|
|
// }
|
|
// //recent 10 articles
|
|
// for (const dat of index.articles.filter((article) => article.publish == "public").list.slice(0, 10)) {
|
|
// if (!dat) continue;
|
|
// data.recent.push({
|
|
// title: dat.title,
|
|
// image: dat.image,
|
|
// date: ((date) => {
|
|
// {
|
|
// // YYYY/MM/DD
|
|
// return `${date.getFullYear()}/${(date.getMonth() + 1).toString().padStart(2, '0')}/${date
|
|
// .getDate()
|
|
// .toString()
|
|
// .padStart(2, '0')}`;
|
|
// }
|
|
// })(dat.released),
|
|
// link: dat.series
|
|
// ? `/post/${dat.category}/${dat.series}/${dat.id}`
|
|
// : `/post/${dat.category}/${dat.id}`,
|
|
// tags: dat.tags
|
|
// });
|
|
// }
|
|
|
|
// return data;
|
|
// };
|