feat: add index page

This commit is contained in:
2024-08-17 16:13:24 +09:00
parent 69688e589b
commit d8af687361
7 changed files with 743 additions and 2 deletions
+89
View File
@@ -0,0 +1,89 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
// import index from '$lib/index';
import type { Content } from '$lib/article';
import pool from '$lib/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 connect = await pool.connect();
const result = await connect.query('SELECT NOW()')
.then((res) => {
data.updated = res.rows[0].now.toISOString();
})
.catch((err) => {
error(err);
});
connect.release();
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;
// };