Skip to content

Commit

Permalink
Make link slugs more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermercer committed Feb 7, 2025
1 parent 1fed440 commit 6a7c7b8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"satori": "^0.10.9",
"satori-html": "^0.3.2",
"sharp": "^0.32.6",
"slugify": "^1.6.6",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/components/LinkCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import getLinkDate from "@utils/getLinkDate";
import type { CollectionEntry } from "astro:content";
import formatPostDate from "../utils/formatPostDate";
import getLinkSlug from "@utils/getLinkSlug";
export type Props = {
link: CollectionEntry<"links">;
Expand All @@ -22,7 +23,7 @@ const l = link;
</hgroup>
<Content />
<p class="date u-slub">
<a href={`/links/${l.slug}`}>
<a href={`/links/${getLinkSlug(l)}`}>
<time datetime={getLinkDate(l.slug).toISOString()}>
{formatPostDate(getLinkDate(l.slug))}
</time>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/links/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import LinkCard from "@components/LinkCard.astro";
import Layout from "@layouts/Base.astro";
import formatPostDate from "@utils/formatPostDate";
import getLinkDate from "@utils/getLinkDate";
import getLinkSlug from "@utils/getLinkSlug";
import { type CollectionEntry, getCollection } from "astro:content";
import unMarkdown from "lib/utils/unMarkdown";
export async function getStaticPaths() {
const links = await getCollection("links");
return links.map((entry) => ({
params: { slug: entry.slug },
return links.map((entry: CollectionEntry<"links">) => ({
params: { slug: getLinkSlug(entry) },
props: { entry },
}));
}
Expand Down
12 changes: 12 additions & 0 deletions src/utils/getLinkSlug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { CollectionEntry } from "astro:content";
import slugify from "slugify";
import getLinkDate from "./getLinkDate";

export default function getLinkSlug(link: CollectionEntry<'links'>) {
const date = getLinkDate(link.slug);
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
return slugify(
`${date.getFullYear()}-${month}-${day}-${link.data.title}`,
).toLowerCase();
}

0 comments on commit 6a7c7b8

Please sign in to comment.