mirror of
https://github.com/kogakure/website-astro-stefanimhoff.de.git
synced 2026-02-03 20:15:27 +00:00
refactor: replace custom implementations with helper
This commit is contained in:
@@ -3,7 +3,7 @@ import cx from 'classnames';
|
|||||||
|
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
import { sortByDate } from '../utils';
|
import { formatPosts, sortByDate } from '../utils';
|
||||||
import { dateToFormat, dateToISO, wordCount } from '../utils';
|
import { dateToFormat, dateToISO, wordCount } from '../utils';
|
||||||
|
|
||||||
import GridLayout from '../layouts/GridLayout.astro';
|
import GridLayout from '../layouts/GridLayout.astro';
|
||||||
@@ -17,17 +17,17 @@ import { mapping } from '../mdx-components';
|
|||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const journalEntries = await getCollection('journal');
|
const journalEntries = await getCollection('journal');
|
||||||
const numberOfPages = journalEntries.length;
|
const numberOfPages = journalEntries.length;
|
||||||
journalEntries.sort(sortByDate).reverse();
|
const formattedJournalEntries = formatPosts(journalEntries, { sortOrder: 'asc' });
|
||||||
|
|
||||||
return journalEntries.map((entry, index) => ({
|
return formattedJournalEntries.map((entry, index) => ({
|
||||||
params: { slug: entry.slug },
|
params: { slug: entry.slug },
|
||||||
props: {
|
props: {
|
||||||
entry,
|
entry,
|
||||||
next:
|
next:
|
||||||
index + 1 === numberOfPages
|
index + 1 === numberOfPages
|
||||||
? { slug: null, data: null }
|
? { slug: null, data: null }
|
||||||
: journalEntries[index + 1],
|
: formattedJournalEntries[index + 1],
|
||||||
prev: index === 0 ? {} : journalEntries[index - 1],
|
prev: index === 0 ? {} : formattedJournalEntries[index - 1],
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
import { sortByDate } from '../utils';
|
import { formatPosts } from '../utils';
|
||||||
|
|
||||||
import GridLayout from '../layouts/GridLayout.astro';
|
import GridLayout from '../layouts/GridLayout.astro';
|
||||||
import PageTitle from '../components/PageTitle.astro';
|
import PageTitle from '../components/PageTitle.astro';
|
||||||
@@ -12,10 +12,10 @@ import { Content as Intro } from '../text/journal/intro.mdx';
|
|||||||
|
|
||||||
import { mapping } from '../mdx-components';
|
import { mapping } from '../mdx-components';
|
||||||
|
|
||||||
const allJournal = await getCollection('journal');
|
const allPosts = await getCollection('journal');
|
||||||
allJournal.sort(sortByDate);
|
const formattedAllPosts = formatPosts(allPosts, {});
|
||||||
|
|
||||||
const uniqueTags = [...new Set(allJournal.map((entry) => entry.data.tags).flat())];
|
const uniqueTags = [...new Set(formattedAllPosts.map((entry) => entry.data.tags).flat())];
|
||||||
uniqueTags.sort((a, b) => a.localeCompare(b));
|
uniqueTags.sort((a, b) => a.localeCompare(b));
|
||||||
|
|
||||||
const title = 'Journal';
|
const title = 'Journal';
|
||||||
@@ -33,5 +33,5 @@ const description = '…';
|
|||||||
<aside class="col-start-1 col-end-18 flex flex-wrap gap-y-3">
|
<aside class="col-start-1 col-end-18 flex flex-wrap gap-y-3">
|
||||||
{uniqueTags.map((tag) => <Tag href={`/tag/${tag}/`}>{tag}</Tag>)}
|
{uniqueTags.map((tag) => <Tag href={`/tag/${tag}/`}>{tag}</Tag>)}
|
||||||
</aside>
|
</aside>
|
||||||
<JournalList entries={allJournal} />
|
<JournalList entries={formattedAllPosts} />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
---
|
---
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
import { sortByDate } from '../utils';
|
|
||||||
|
|
||||||
import GridLayout from '../layouts/GridLayout.astro';
|
import GridLayout from '../layouts/GridLayout.astro';
|
||||||
import PageTitle from '../components/PageTitle.astro';
|
import PageTitle from '../components/PageTitle.astro';
|
||||||
import { Tag } from '../components';
|
import { Tag as TagComponent } from '../components';
|
||||||
|
|
||||||
const allJournal = await getCollection('journal');
|
const allJournal = await getCollection('journal');
|
||||||
allJournal.sort(sortByDate);
|
|
||||||
|
|
||||||
const uniqueTags = [...new Set(allJournal.map((entry) => entry.data.tags).flat())];
|
const uniqueTags = [...new Set(allJournal.map((entry) => entry.data.tags).flat())];
|
||||||
uniqueTags.sort((a, b) => a.localeCompare(b));
|
uniqueTags.sort((a, b) => a.localeCompare(b));
|
||||||
|
|
||||||
@@ -27,6 +23,6 @@ const description = '…';
|
|||||||
>
|
>
|
||||||
<PageTitle grid="wide" innerGrid>Tags</PageTitle>
|
<PageTitle grid="wide" innerGrid>Tags</PageTitle>
|
||||||
<aside class="col-start-1 col-end-18 flex flex-wrap gap-y-3">
|
<aside class="col-start-1 col-end-18 flex flex-wrap gap-y-3">
|
||||||
{uniqueTags.map((t) => <Tag href={`/tag/${t}/`}>{t}</Tag>)}
|
{uniqueTags.map((t) => <TagComponent href={`/tag/${t}/`}>{t}</TagComponent>)}
|
||||||
</aside>
|
</aside>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
import { sortByDate } from '../../utils';
|
import { formatPosts } from '../../utils';
|
||||||
|
|
||||||
import GridLayout from '../../layouts/GridLayout.astro';
|
import GridLayout from '../../layouts/GridLayout.astro';
|
||||||
import PageTitle from '../../components/PageTitle.astro';
|
import PageTitle from '../../components/PageTitle.astro';
|
||||||
@@ -16,13 +16,15 @@ interface Props {
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const journalEntries = await getCollection('journal');
|
const journalEntries = await getCollection('journal');
|
||||||
journalEntries.sort(sortByDate);
|
const formattedJournalEntries = formatPosts(journalEntries, {});
|
||||||
|
|
||||||
const uniqueTags = [...new Set(journalEntries.map((entry) => entry.data.tags).flat())];
|
const uniqueTags = [...new Set(formattedJournalEntries.map((entry) => entry.data.tags).flat())];
|
||||||
uniqueTags.sort((a, b) => a.localeCompare(b));
|
uniqueTags.sort((a, b) => a.localeCompare(b));
|
||||||
|
|
||||||
return uniqueTags.map((tag) => {
|
return uniqueTags.map((tag) => {
|
||||||
const filteredEntries = journalEntries.filter((entry) => entry.data.tags.includes(tag));
|
const filteredEntries = formattedJournalEntries.filter((entry) =>
|
||||||
|
entry.data.tags.includes(tag)
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
params: { tag },
|
params: { tag },
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { defineCollection, z } from 'astro:content';
|
|||||||
export const journal = defineCollection({
|
export const journal = defineCollection({
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
|
draft: z.boolean().optional().default(false),
|
||||||
featured: z.boolean().optional(),
|
featured: z.boolean().optional(),
|
||||||
author: z.string().default('Stefan Imhoff'),
|
author: z.string().default('Stefan Imhoff'),
|
||||||
date: z.date(),
|
date: z.date(),
|
||||||
|
|||||||
Reference in New Issue
Block a user