2022-11-03 15:12:03 +01:00
|
|
|
import type { GetServerSideProps, NextPage } from "next";
|
2022-10-29 22:17:00 +02:00
|
|
|
import Link from "next/link";
|
2022-10-27 15:33:19 +02:00
|
|
|
import gen from "random-seed";
|
2022-10-16 00:05:44 +02:00
|
|
|
import Layout from "../components/Blog/Layout";
|
2022-10-18 17:38:11 +02:00
|
|
|
import type { ContentList, Project, Diary } from "../lib/content/types";
|
2022-09-30 19:23:14 +02:00
|
|
|
import ProjectCard from "../components/Blog/Card";
|
2022-10-08 13:37:28 +02:00
|
|
|
import { getContentList } from "../lib/content/generateBackend";
|
2022-10-07 23:03:39 +02:00
|
|
|
|
2022-10-01 14:04:21 +02:00
|
|
|
import styles from "../styles/Blog/Front.module.scss";
|
2021-11-30 23:48:54 +01:00
|
|
|
|
2022-10-18 17:38:11 +02:00
|
|
|
|
2022-10-03 01:20:17 +02:00
|
|
|
const Blog: NextPage<{ content: ContentList }> = ({content}) => {
|
2022-10-18 17:38:11 +02:00
|
|
|
const clearDescription = (description: string) => {
|
|
|
|
const linkRegex = /#%\{([a-z0-9 \.-\/:]*)\|([a-z0-9 \/:\.-]*)\}/ig;
|
|
|
|
const cmdRegex = /%\{([a-z0-9 \.-\/:]*)}/ig;
|
|
|
|
|
|
|
|
return description.replace(linkRegex, "$1").replace(cmdRegex, "\"$1\"");
|
|
|
|
};
|
|
|
|
|
2022-10-27 15:33:19 +02:00
|
|
|
const shuffleArray = (arr: any[]) => {
|
|
|
|
// We want shuffle but only between days
|
|
|
|
const date = new Date();
|
|
|
|
const generator = gen.create(`${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`);
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/6274381
|
|
|
|
for (let i = arr.length - 1; i > 0; i--) {
|
|
|
|
const j = generator.intBetween(0, i);
|
|
|
|
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
|
|
}
|
|
|
|
generator.done();
|
|
|
|
return arr;
|
|
|
|
};
|
|
|
|
|
2022-09-30 19:38:25 +02:00
|
|
|
const generateCards = (type: string) => {
|
2022-10-18 17:38:11 +02:00
|
|
|
return <div className={styles.contentList}>{
|
2022-10-27 15:33:19 +02:00
|
|
|
(shuffleArray(content.filter(p => p.type === type)) as (Project|Diary)[])
|
2022-10-18 17:38:11 +02:00
|
|
|
.map(p =>
|
|
|
|
<ProjectCard key={p.name} title={p.title} description={clearDescription(p.desc.join(" "))} type={p.type} name={p.name} />
|
|
|
|
)}
|
|
|
|
</div>;
|
2022-09-30 19:38:25 +02:00
|
|
|
};
|
|
|
|
|
2022-10-18 23:40:09 +02:00
|
|
|
return <Layout>
|
|
|
|
<h1>Hello there!</h1>
|
2022-10-29 22:17:00 +02:00
|
|
|
<p className={styles.frontText}>
|
|
|
|
Welcome to my website!<br/>
|
|
|
|
You can find here blog entries about some projects I did and some diaries where I document progress.<br/>
|
|
|
|
Interested in me? Visit the <Link href="/me"><a className="nocolor">About Me page</a></Link>, and you will find out more about me.<br/>
|
|
|
|
On the right of the navigation, you will find what used to be my website - a CLI you can play around with.<br/><br/>
|
|
|
|
Have fun!
|
|
|
|
</p>
|
2022-10-18 23:40:09 +02:00
|
|
|
<h2>Projects</h2>
|
|
|
|
{ generateCards("project") }
|
|
|
|
<h2>Diaries</h2>
|
|
|
|
{ generateCards("diary") }
|
|
|
|
</Layout>;
|
2022-09-30 19:23:14 +02:00
|
|
|
|
2022-06-14 19:07:21 +02:00
|
|
|
};
|
|
|
|
|
2022-11-03 15:12:03 +01:00
|
|
|
export const getServerSideProps: GetServerSideProps = async ({ res }) => {
|
|
|
|
res.setHeader("Cache-Control", "public, s-maxage=3600, stale-while-revalidate=600");
|
|
|
|
|
2022-10-08 13:37:28 +02:00
|
|
|
return { props: { content: await getContentList() } };
|
2022-11-03 15:12:03 +01:00
|
|
|
};
|
2022-10-03 01:20:17 +02:00
|
|
|
|
2022-09-30 19:23:14 +02:00
|
|
|
export default Blog;
|