Skip to content

Commit 5edb286

Browse files
committed
feat: add projects
1 parent a575f82 commit 5edb286

22 files changed

+207
-54
lines changed

.changeset/tired-hoops-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"r.obin.ch": minor
3+
---
4+
5+
Add projects

src/collections/notes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCollection } from "astro:content";
22
import type { GitInfoFrontmatter } from "../remark/remark-git-info";
33

4-
export type Note = { path: string, title: string, gitInfo: GitInfoFrontmatter["git"] };
4+
export type Note = { path: string, title: string, gitInfo?: GitInfoFrontmatter };
55
export type NestedNotes = {
66
[key: string]: NestedNotes | { note: Note };
77
};

src/collections/projects.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1-
import { getCollection } from "astro:content";
1+
import { getCollection, render } from "astro:content";
2+
import { getGitInfo } from "../remark/remark-git-info";
23

3-
export const defaultProjectsCollection = await getCollection("projects");
4+
const projectsCollection = await getCollection("projects");
5+
const projectsContentCollection = await getCollection("projectsContent");
6+
7+
export const defaultProjectsCollection = await Promise.all(
8+
projectsContentCollection.map(async (content) => {
9+
const project = projectsCollection.find(
10+
(project) => project.data.contentPath === content.data.contentPath
11+
);
12+
if (!project) {
13+
throw new Error(
14+
`Project not found for contentPath: ${content.data.contentPath}`
15+
);
16+
}
17+
const { remarkPluginFrontmatter } = await render(content);
18+
const gitInfo = getGitInfo(remarkPluginFrontmatter);
19+
return {
20+
...content,
21+
data: {
22+
gitInfo,
23+
...project.data,
24+
...content.data,
25+
},
26+
};
27+
})
28+
);

src/components/GitInfo.astro

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import Button from './Button.astro';
55
import DateTime from './DateTime.astro';
66
import Foldable from './Foldable.astro';
77
8-
type Props = GitInfoFrontmatter;
8+
type Props = { gitInfo?: GitInfoFrontmatter };
99
10-
const { git } = Astro.props;
10+
const { gitInfo } = Astro.props;
1111
const locale = parseLocale(Astro.currentLocale);
1212
const t = useTranslations(locale);
1313
@@ -17,16 +17,16 @@ const t = useTranslations(locale);
1717
<span class="label" slot="title">{t('gitInfoLabel')}</span>
1818
<dl>
1919
<slot name="before" />
20-
{git?.lastCommit && (
20+
{gitInfo?.lastCommit && (
2121
<dt>{t('authorLabel')}</dt>
22-
<dd>{git.lastCommit.authorName}</dd>
22+
<dd>{gitInfo.lastCommit.authorName}</dd>
2323
<dt>{t('lastUpdatedLabel')}</dt>
24-
<dd><DateTime date={new Date(git.lastCommit.date)} /></dd>
24+
<dd><DateTime date={new Date(gitInfo.lastCommit.date)} /></dd>
2525
<dt>{t('linksLabel')}</dt>
2626
<dd>
27-
<Button href={git.remoteViewUrl}>{t('sourceLabel')}</Button>
28-
<Button href={git.remoteHistoryUrl}>{t('historyLabel')}</Button>
29-
<Button href={git.remoteEditUrl}>{t('editLabel')}</Button>
27+
<Button href={gitInfo.remoteViewUrl}>{t('sourceLabel')}</Button>
28+
<Button href={gitInfo.remoteHistoryUrl}>{t('historyLabel')}</Button>
29+
<Button href={gitInfo.remoteEditUrl}>{t('editLabel')}</Button>
3030
</dd>
3131
)}
3232
<slot name="after" />

src/components/NoteListEntry.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import DateTime from "./DateTime.astro";
55
type Props = {
66
path: string;
77
title: string;
8-
gitInfo: GitInfoFrontmatter["git"];
8+
gitInfo?: GitInfoFrontmatter;
99
};
1010
1111
const { path, title, gitInfo } = Astro.props;
@@ -23,7 +23,7 @@ const { path, title, gitInfo } = Astro.props;
2323
<a href={path}>
2424
<span class="note-title">{title}</span>
2525
{
26-
gitInfo.lastCommit && (
26+
gitInfo?.lastCommit && (
2727
<span class="note-modified">
2828
<DateTime date={new Date(gitInfo.lastCommit?.date)} dateStyle="short" />
2929
</span>

src/content.config.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ const galleryCollection = defineCollection({
4545
),
4646
});
4747
const projectsCollection = defineCollection({
48-
loader: glob({ pattern: "**/[^_]*.{md,mdx}", base: "./src/content/projects" }),
49-
schema: ({ image }) =>
48+
loader: i18nContentLoader({ pattern: "**/[^_]*.yml", base: "./src/content/projects" }),
49+
schema: ({ image }) => extendI18nLoaderSchema(
5050
z.object({
51-
title: z.string(),
52-
summary: z.string(),
5351
homepage: z.string().url().optional(),
5452
source: z.string().url().optional(),
5553
cover: image().optional(),
54+
status: z.enum(["active", "maintenance", "archived"]),
55+
type: z.enum(["website", "app", "library", "tool", "other"]),
5656
images: z.array(
5757
z.object({
5858
src: image(),
@@ -61,6 +61,16 @@ const projectsCollection = defineCollection({
6161
}),
6262
).optional(),
6363
}),
64+
),
65+
});
66+
const projectsContentCollection = defineCollection({
67+
loader: i18nLoader({ pattern: "**/[^_]*.{md,mdx}", base: "./src/content/projects" }),
68+
schema: extendI18nLoaderSchema(
69+
z.object({
70+
title: z.string(),
71+
summary: z.string(),
72+
}),
73+
),
6474
});
6575
const pagesCollection = defineCollection({
6676
loader: i18nLoader({ pattern: "**/[^_]*.{md,mdx}", base: "./src/content/pages" }),
@@ -96,6 +106,7 @@ export const collections = {
96106
notes: notesCollection,
97107
gallery: galleryCollection,
98108
projects: projectsCollection,
109+
projectsContent: projectsContentCollection,
99110
pages: pagesCollection,
100111
navigation: navigationCollection,
101112
sections: sectionsCollection,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Astro-Loader für Internationalisierung und Lokalisierung
3+
summary: Ein Astro Glob Loader für i18n-Dateien und Ordnerstrukturen.
4+
---
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Astro Loader for Internationalization and Localization
3+
summary: An Astro glob content loader for i18n files and folder structures.
4+
---
5+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
homepage: https://www.npmjs.com/package/astro-loader-i18n
2+
source: https://github.com/openscript/astro-loader-i18n
3+
status: active
4+
type: library

src/content/projects/gatsby-plugin-i18n-l10n.de.mdx

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Gatsby-Plugin für Internationalisierung und Lokalisierung
3+
summary: Gatsby-Plugin, der es ermöglicht, Seiten, Inhalte und die URLs oder Slugs von Seiten zu übersetzen.
4+
---
5+
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
---
22
title: Gatsby Plugin for internationalization and localization
33
summary: Gatsby Plugin, that let you translate pages, content and the url or slugs of pages.
4-
homepage: https://www.gatsbyjs.com/plugins/gatsby-plugin-i18n-l10n
5-
source: https://github.com/openscript-ch/gatsby-plugin-i18n-l10n
64
---
75

8-
Test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
homepage: https://www.gatsbyjs.com/plugins/gatsby-plugin-i18n-l10n
2+
source: https://github.com/openscript-ch/gatsby-plugin-i18n-l10n
3+
status: maintenance
4+
type: library

src/env.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/// <reference path="../.astro/types.d.ts" />
22

3-
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
4-
53
export {};
64

75
declare global {

src/pages/[...locale]/[...pages].astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const getStaticPaths = async () => {
1717
};
1818
1919
const page = Astro.props;
20-
2120
const { Content } = await render(page);
2221
---
2322

src/pages/[...locale]/[blog]/[...slug].astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import DefaultLayout from "../../../layouts/DefaultLayout.astro";
33
import Post from "../../../layouts/pages/Post.astro";
44
import TableOfContents from "../../../components/TableOfContents.astro";
55
import GitInfo from "../../../components/GitInfo.astro";
6-
import type { GitInfoFrontmatter } from "../../../remark/remark-git-info";
6+
import { getGitInfo } from "../../../remark/remark-git-info";
77
import { parseLocale, useTranslations } from "../../../utils/i18n";
88
import Comments from "../../../components/Comments.astro";
99
import Meta from "../../../layouts/groups/Meta.astro";
@@ -41,7 +41,7 @@ const blogPath =
4141
? originalResolvePath(paramsBlog)
4242
: originalResolvePath(locale, paramsBlog);
4343
44-
const git: GitInfoFrontmatter["git"] = remarkPluginFrontmatter.git;
44+
const gitInfo = getGitInfo(remarkPluginFrontmatter);
4545
const t = useTranslations(parseLocale(locale));
4646
---
4747

@@ -52,7 +52,7 @@ const t = useTranslations(parseLocale(locale));
5252
<Content />
5353
<Comments />
5454
<Fragment slot="right">
55-
<GitInfo git={git}>
55+
<GitInfo gitInfo={gitInfo}>
5656
<Fragment slot="after">
5757
<dt>{t("tagsLabel")}</dt>
5858
<dd>

src/pages/[...locale]/[gallery]/index.astro

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import GalleryCard from "../../../components/GalleryCard.astro";
88
import { generateGetStaticIndexPaths, resolvePath } from "../../../utils/paths";
99
import { C } from "../../../site.config";
1010
import slug from "limax";
11+
import Meta from "../../../layouts/groups/Meta.astro";
1112
1213
export const getStaticPaths = generateGetStaticIndexPaths(
1314
"[...locale]/[gallery]",
1415
);
15-
const { translations } = Astro.props;
16+
const { translations, data: { locale } } = Astro.props;
1617
17-
const locale = parseLocale(Astro.props.data.locale);
1818
const localeParam = locale === C.DEFAULT_LOCALE ? undefined : locale;
1919
const collection = await getCollection(
2020
"gallery",
2121
(category) => category.data.locale === locale,
2222
);
23-
const t = useTranslations(locale);
23+
const t = useTranslations(parseLocale(locale));
2424
---
2525

2626

@@ -33,8 +33,9 @@ const t = useTranslations(locale);
3333
</style>
3434

3535
<DefaultLayout translations={translations}>
36+
<Meta slot="meta" title={t("galleryTitle")} />
3637
<Page>
37-
<h1>{t("galleryTitle")}</h1>
38+
<h1 slot="title">{t("galleryTitle")}</h1>
3839
<CardList classNames="grid">
3940
{
4041
collection

src/pages/[...locale]/[notes]/index.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { defaultPropsAndParamsOptions, generateGetStaticIndexPaths } from "../..
88
import { i18nProps } from "astro-loader-i18n";
99
import slug from "limax";
1010
import { defaultNotesCollection } from "../../../collections/notes";
11-
import type { GitInfoFrontmatter } from "../../../remark/remark-git-info";
11+
import { getGitInfo, type GitInfoFrontmatter } from "../../../remark/remark-git-info";
1212
import { render } from "astro:content";
1313
1414
export const getStaticPaths = generateGetStaticIndexPaths(
@@ -29,13 +29,13 @@ const notes = i18nProps(collection, {
2929
});
3030
3131
type NestedNotes = {
32-
[key: string]: NestedNotes | { note: { path: string; title: string; gitInfo: GitInfoFrontmatter["git"] } };
32+
[key: string]: NestedNotes | { note: { path: string; title: string; gitInfo?: GitInfoFrontmatter } };
3333
};
3434
3535
const notesWithGitInfo = await Promise.all(
3636
notes.map(async (note) => {
3737
const { remarkPluginFrontmatter } = await render(note);
38-
const gitInfo = remarkPluginFrontmatter?.git as GitInfoFrontmatter["git"];
38+
const gitInfo = getGitInfo(remarkPluginFrontmatter)
3939
return {
4040
...note,
4141
gitInfo,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
import { i18nPropsAndParams } from "astro-loader-i18n";
3+
import { defaultProjectsCollection } from "../../../collections/projects";
4+
import { defaultPropsAndParamsOptions } from "../../../utils/paths";
5+
import DefaultLayout from "../../../layouts/DefaultLayout.astro";
6+
import Meta from "../../../layouts/groups/Meta.astro";
7+
import { render } from "astro:content";
8+
import Page from "../../../layouts/pages/Page.astro";
9+
10+
export const getStaticPaths = async () => {
11+
const routePattern = "[...locale]/[projects]/[project]";
12+
13+
return i18nPropsAndParams(defaultProjectsCollection, {
14+
...defaultPropsAndParamsOptions,
15+
routePattern,
16+
generateSegments: (entry) => ({ project: entry.data.contentPath }),
17+
});
18+
};
19+
20+
const page = Astro.props;
21+
22+
console.log(page.data);
23+
const { Content } = await render(page);
24+
---
25+
26+
<DefaultLayout translations={page.translations}>
27+
<Meta slot="meta" title={page.data.title} />
28+
<Page>
29+
<h1 slot="title">{page.data.title}</h1>
30+
<p>{page.data.summary}</p>
31+
<Content />
32+
</Page>
33+
</DefaultLayout>

0 commit comments

Comments
 (0)