diff --git a/src/components/Tag.tsx b/src/components/Tag.tsx index f642a87..f2a7440 100644 --- a/src/components/Tag.tsx +++ b/src/components/Tag.tsx @@ -2,20 +2,43 @@ import cx from 'classnames'; import type { ComponentChild, FunctionalComponent } from 'preact'; +import { Link } from '.'; + interface Props { - class?: string; + active?: boolean; children: ComponentChild; + class?: string; + href?: string; } -export const Tag: FunctionalComponent = ({ class: className, children, ...props }) => { +export const Tag: FunctionalComponent = ({ + active, + class: className, + children, + href, + ...props +}) => { const classes = cx( - 'inline-flex items-center justify-center rounded-25 border-2 border-shibui-350 bg-shibui-200 px-3 py-1 text-1 leading-none text-black mie-1 dark:border-shibui-750 dark:bg-shibui-950 dark:text-white', + 'capitalize border-3 relative inline-flex items-center justify-center rounded-25 border-2 border-shibui-350 bg-shibui-200 px-3 py-1 text-1 font-normal leading-none text-black mie-1 pbs-3 dark:border-shibui-750 dark:bg-shibui-950 dark:text-white min-w-[50px]', + { + '!bg-shibui-500 !text-white hover:!bg-shibui-700 dark:!border-shibui-500 dark:!bg-shibui-700 hover:dark:!bg-shibui-400': + href, + 'active [&.active]:!border-black/25 !text-white [&.active]:!bg-accent': active, + }, className ); return ( - - {children} - + <> + {href ? ( + + {children} + + ) : ( + + {children} + + )} + ); }; diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index 7ec47f5..5aa6253 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -10,7 +10,7 @@ import GridLayout from '../layouts/GridLayout.astro'; import PageTitle from '../components/PageTitle.astro'; import Pagination from '../components/Pagination.astro'; import Picture from '../components/Picture.astro'; -import { Banner, ListItem, OrderedList, TextLink } from '../components'; +import { Banner, ListItem, OrderedList, Tag, TextLink } from '../components'; import { mapping } from '../mdx-components'; @@ -52,14 +52,13 @@ const description = '…'; {entry.data.title} - { entry.data.cover && ( @@ -79,11 +78,14 @@ const description = '…';
-
+
{wordCount(entry.body)} words • {minutesRead} read
+
+ {entry.data.tags.map((t) => {t})} +
entry.data.tags).flat())]; +uniqueTags.sort((a, b) => a.localeCompare(b)); + +const title = 'Tags'; +const description = '…'; +--- + + + Tags + + diff --git a/src/pages/tags/[tag].astro b/src/pages/tag/[tag].astro similarity index 64% rename from src/pages/tags/[tag].astro rename to src/pages/tag/[tag].astro index 830ba84..d57b795 100644 --- a/src/pages/tags/[tag].astro +++ b/src/pages/tag/[tag].astro @@ -6,14 +6,20 @@ import { sortByDate } from '../../utils'; import GridLayout from '../../layouts/GridLayout.astro'; import PageTitle from '../../components/PageTitle.astro'; import JournalList from '../../components/JournalList.astro'; +import { Tag } from '../../components'; -console.log('test'); +import type { CollectionEntry } from 'astro:content'; +interface Props { + entries: CollectionEntry<'journal'>[]; + uniqueTags: string[]; +} export async function getStaticPaths() { const journalEntries = await getCollection('journal'); journalEntries.sort(sortByDate); const uniqueTags = [...new Set(journalEntries.map((entry) => entry.data.tags).flat())]; + uniqueTags.sort((a, b) => a.localeCompare(b)); return uniqueTags.map((tag) => { const filteredEntries = journalEntries.filter((entry) => entry.data.tags.includes(tag)); @@ -21,13 +27,14 @@ export async function getStaticPaths() { params: { tag }, props: { entries: filteredEntries, + uniqueTags: uniqueTags, }, }; }); } const { tag } = Astro.params; -const { entries } = Astro.props; +const { entries, uniqueTags } = Astro.props; const title = 'Journal'; const description = '…'; @@ -41,8 +48,17 @@ const description = '…'; innerGrid backLink="/journal/" > - - Tag: {tag} + + {tag} +