This commit is contained in:
Morten Olsen
2024-03-30 20:53:01 +01:00
commit 98e39a54cc
94 changed files with 11654 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
---
import { type Article, data } from '@/data/data.js';
import ArticleView from '@/layouts/article/article.astro';
type Props = {
article: Article;
};
const getStaticPaths = async () => {
const articles = await data.articles.find();
return articles.map((article) => ({
params: { slug: article.slug },
props: { article },
}));
};
const { props } = Astro;
const { article } = props;
export { getStaticPaths };
---
<ArticleView article={article} />

View File

@@ -0,0 +1,24 @@
import { type Article, data } from '@/data/data.ts';
import type { APIContext } from 'astro';
type Props = {
article: Article;
};
export async function GET(context: APIContext<Props>) {
const { props } = context;
const { article } = props;
return new Response(JSON.stringify(article), {
headers: {
'Content-Type': 'application/json',
},
});
}
export async function getStaticPaths() {
const articles = await data.articles.find();
return articles.map((article) => ({
params: { slug: article.slug },
props: { article },
}));
}

View File

@@ -0,0 +1,36 @@
---
import { type Article, data } from '@/data/data.js';
import Articles from '@/layouts/articles/articles.astro';
import { range } from '@/utils/data.js';
type Props = {
articles: Article[];
pageNumber: number;
pageCount: number;
pageSize: number;
};
export async function getStaticPaths() {
const pageSize = 2;
const allArticles = await data.articles.find();
const pageCount = Math.ceil(allArticles.length / pageSize);
const pages = range(0, pageCount).map((index) => {
const start = index * pageSize;
const end = start + pageSize;
return {
pageNumber: index + 1,
pageCount,
pageSize,
articles: allArticles.slice(start, end),
};
});
return pages.map((page) => ({
params: { page: String(page.pageNumber) },
props: page,
}));
}
const { props } = Astro;
---
<Articles {...props} />

View File

@@ -0,0 +1,17 @@
import { data } from '@/data/data.ts';
import rss from '@astrojs/rss';
import type { APIContext } from 'astro';
export async function GET(context: APIContext) {
const articles = await data.articles.find();
const profile = data.profile;
return rss({
title: profile.basics.name,
description: profile.basics.tagline,
site: context.site || 'http://localhost:3000',
items: articles.map((article) => ({
...article.data,
link: `/articles/${article.slug}/`,
})),
});
}

6
src/pages/index.astro Normal file
View File

@@ -0,0 +1,6 @@
---
import {} from '@/data/data.js';
import Frontpage from '@/layouts/frontpage/frontpage.astro';
---
<Frontpage />

View File

@@ -0,0 +1,39 @@
import { icons } from '@/assets/images/icons.js';
import { data } from '@/data/data.js';
import type { ManifestOptions } from 'vite-plugin-pwa';
export async function GET() {
const [maskableIcon] = icons.pngs.filter(
(icon) => icon.size === '512x512' && icon.src.includes('png'),
);
const nonMaskableIcons = icons.pngs.filter((icon) => icon !== maskableIcon);
const basics = data.profile.basics;
const manifest: Partial<ManifestOptions> = {
name: basics.name,
short_name: basics.name,
description: basics.tagline,
theme_color: '#30E130',
background_color: data.site.theme,
start_url: '/',
display: 'minimal-ui',
icons: [
...nonMaskableIcons.map((png) => ({
src: png.src,
sizes: png.size,
type: 'image/png',
})),
...(maskableIcon
? [
{
src: maskableIcon.src,
sizes: maskableIcon.size,
type: 'image/png',
purpose: 'maskable',
},
]
: []),
],
};
return new Response(JSON.stringify(manifest, null, 2));
}

6
src/pages/resume.json.ts Normal file
View File

@@ -0,0 +1,6 @@
import { data } from '@/data/data.ts';
export async function GET() {
const resume = await data.getJsonResume();
return new Response(JSON.stringify(resume, null, 2));
}

View File

@@ -0,0 +1,5 @@
---
import Work from '@/layouts/work-history/work-history.astro';
---
<Work />