This commit is contained in:
Morten Olsen
2024-04-19 20:51:52 +02:00
committed by Morten Olsen
parent 98e39a54cc
commit ee37ac9d90
51 changed files with 604 additions and 798 deletions

View File

@@ -1,22 +1,20 @@
---
import { type Article, data } from '@/data/data.js';
import ArticleView from '@/layouts/article/article.astro';
import { type Article, data } from '@/data/data.js'
import ArticleView from '@/layouts/article/article.astro'
type Props = {
article: Article;
};
article: Article
}
const getStaticPaths = async () => {
const articles = await data.articles.find();
export 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 };
props: { article }
}))
}
const { props } = Astro
const { article } = props
---
<ArticleView article={article} />

View File

@@ -1,24 +0,0 @@
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

@@ -1,36 +1,36 @@
---
import { type Article, data } from '@/data/data.js';
import Articles from '@/layouts/articles/articles.astro';
import { range } from '@/utils/data.js';
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;
};
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 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;
const start = index * pageSize
const end = start + pageSize
return {
pageNumber: index + 1,
pageCount,
pageSize,
articles: allArticles.slice(start, end),
};
});
articles: allArticles.slice(start, end)
}
})
return pages.map((page) => ({
params: { page: String(page.pageNumber) },
props: page,
}));
props: page
}))
}
const { props } = Astro;
const { props } = Astro
---
<Articles {...props} />

View File

@@ -1,17 +1,17 @@
import { data } from '@/data/data.ts';
import rss from '@astrojs/rss';
import type { APIContext } from 'astro';
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;
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}/`,
})),
});
link: `/articles/${article.slug}/`
}))
})
}

View File

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

View File

@@ -1,13 +1,13 @@
import { icons } from '@/assets/images/icons.js';
import { data } from '@/data/data.js';
import type { ManifestOptions } from 'vite-plugin-pwa';
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;
(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,
@@ -21,7 +21,7 @@ export async function GET() {
...nonMaskableIcons.map((png) => ({
src: png.src,
sizes: png.size,
type: 'image/png',
type: 'image/png'
})),
...(maskableIcon
? [
@@ -29,11 +29,11 @@ export async function GET() {
src: maskableIcon.src,
sizes: maskableIcon.size,
type: 'image/png',
purpose: 'maskable',
},
purpose: 'maskable'
}
]
: []),
],
};
return new Response(JSON.stringify(manifest, null, 2));
: [])
]
}
return new Response(JSON.stringify(manifest, null, 2))
}

View File

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

View File

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