From 272a4b13267726dc38117ca9ef6188622d699236 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 12 Apr 2021 18:31:03 -0400 Subject: [PATCH] slugify tag paths --- lib/generate/posts.ts | 2 ++ lib/generate/tags.ts | 3 ++- lib/metadata.ts | 1 + site/includes/article-meta.html.ejs | 2 +- site/posts/2021-04-12-lets-build-a-programming-language.md | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/generate/posts.ts b/lib/generate/posts.ts index 3923766..15ab29e 100644 --- a/lib/generate/posts.ts +++ b/lib/generate/posts.ts @@ -11,6 +11,8 @@ import layout from "../layout"; async function generatePostFromFile(postPath: string, additionalMetadata: object = {}): Promise { const page = await metadata.get(postPath); + (page.metadata).tagSlugs = (page.metadata).tags.map((tag) => slugify(tag)); + for (const k in additionalMetadata) { if (additionalMetadata.hasOwnProperty(k)) page.metadata[k] = additionalMetadata[k]; } diff --git a/lib/generate/tags.ts b/lib/generate/tags.ts index 67d5928..9225ce7 100644 --- a/lib/generate/tags.ts +++ b/lib/generate/tags.ts @@ -1,5 +1,6 @@ import { Page, PostMetadata } from "../metadata"; import generatePaginated from "./paginated"; +import slugify from "@sindresorhus/slugify"; export default async function(posts: Page[]): Promise> { const taggedPosts = new Map(); @@ -15,7 +16,7 @@ export default async function(posts: Page[]): Promise> { } taggedPosts.forEach((tagPosts, tag) => { - generatePaginated(tagPosts, `/${tag}/`, "site/tag.html.ejs", { + generatePaginated(tagPosts, `/${slugify(tag)}/`, "site/tag.html.ejs", { tag }, { title: `${tag} posts` diff --git a/lib/metadata.ts b/lib/metadata.ts index 666908e..272ec25 100644 --- a/lib/metadata.ts +++ b/lib/metadata.ts @@ -17,6 +17,7 @@ export interface PostMetadata extends Metadata { title: string; slug: string; tags: string[]; + tagSlugs: string[]; date: string | Date; readingTime?: number; wordCount?: number; diff --git a/site/includes/article-meta.html.ejs b/site/includes/article-meta.html.ejs index 5006b1f..1195779 100644 --- a/site/includes/article-meta.html.ejs +++ b/site/includes/article-meta.html.ejs @@ -11,7 +11,7 @@ <% if (metadata.tags) { %> in <% for (let i = 0; i < metadata.tags.length; i++) { %> - <%= i < metadata.tags.length - 1 ? ", " : "" %> + <%= i < metadata.tags.length - 1 ? ", " : "" %> <% } %> <% } else if (metadata.series) { %> in diff --git a/site/posts/2021-04-12-lets-build-a-programming-language.md b/site/posts/2021-04-12-lets-build-a-programming-language.md index 366a5d3..54b94d3 100644 --- a/site/posts/2021-04-12-lets-build-a-programming-language.md +++ b/site/posts/2021-04-12-lets-build-a-programming-language.md @@ -1,6 +1,6 @@ ``` metadata.title = "Let's Build a Programming Language: Part 0" -metadata.tags = ["let's build a programming language", "rust"] +metadata.tags = ["build a programming language", "rust"] metadata.date = "2021-04-12 17:27:42 -0400" metadata.shortDesc = "" metadata.slug = "lets-build-a-programming-language"