From cf5e77b00b333dd7d0c1a7f7e4e975e91549f3db Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 13 Mar 2025 18:25:26 +0000 Subject: [PATCH] feat: add the tags property to the BlogPost item --- src/lib/blog/BlogPost.test.ts | 2 ++ src/lib/blog/BlogPost.ts | 3 +++ src/lib/blog/markdown-repository.ts | 7 +++---- src/lib/blog/test-builders/blog-post-builder.ts | 12 ++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/lib/blog/BlogPost.test.ts b/src/lib/blog/BlogPost.test.ts index c03ca09..5eb7873 100644 --- a/src/lib/blog/BlogPost.test.ts +++ b/src/lib/blog/BlogPost.test.ts @@ -14,6 +14,7 @@ describe('BlogPost', () => { fileName: `the-file-name.md`, html: 'Test Content', excerpt: 'Test Excerpt', + tags: [], }); // THEN @@ -25,6 +26,7 @@ describe('BlogPost', () => { .withHtml('Test Content') .withExcerpt('Test Excerpt') .withFileName(`the-file-name.md`) + .withEmptyTags() .build(); expect(blogPost).toStrictEqual(expectedBlogPost); diff --git a/src/lib/blog/BlogPost.ts b/src/lib/blog/BlogPost.ts index 824d233..06de4a3 100644 --- a/src/lib/blog/BlogPost.ts +++ b/src/lib/blog/BlogPost.ts @@ -6,6 +6,7 @@ interface BlogPostParams { fileName: string; // excluding any leading `..` html: string; excerpt: string; + tags: string[]; } export class BlogPost { @@ -16,6 +17,7 @@ export class BlogPost { readonly fileName: string; public readonly html: string; public readonly excerpt: string; + public readonly tags: string[] = []; constructor(params: BlogPostParams) { this.title = params.title; @@ -25,5 +27,6 @@ export class BlogPost { this.fileName = params.fileName.split(`/`)[-1]; this.html = params.html; this.excerpt = params.excerpt; + this.tags = params.tags; } } diff --git a/src/lib/blog/markdown-repository.ts b/src/lib/blog/markdown-repository.ts index 377dfc3..3671160 100644 --- a/src/lib/blog/markdown-repository.ts +++ b/src/lib/blog/markdown-repository.ts @@ -7,15 +7,12 @@ import { BookReviewSet } from './BookReviewSet.js'; import { BookReview } from './BookReview.js'; import { SnoutStreetStudiosPost } from '$lib/snout-street-studios/SnoutStreetStudiosPost.js'; import { SnoutStreetStudiosPostSet } from './SnoutStreetStudiosPostSet.js'; -import { MarkdownBuilder } from './markdown/markdown-builder.js'; // We have to duplicate the `../..` here because import.meta must have a static string, // and it (rightfully) cannot have dynamic locations const blogPostMetaGlobImport = import.meta.glob(`../../content/blog/*.md`, { as: 'raw' }); const bookReviewsMetaGlobImport = import.meta.glob(`../../content/book-reviews/*.md`, { as: 'raw' }); -const snoutStreetStudiosPostMetaGlobImport = import.meta.glob('../../content/snout-street-studios/*.md', { - as: 'raw', -}); +const snoutStreetStudiosPostMetaGlobImport = import.meta.glob('../../content/snout-street-studios/*.md', { as: 'raw' }); interface BlogPostFrontmatterValues { title: string; @@ -93,6 +90,7 @@ export class MarkdownRepository { author: markdownFile.frontmatter.author, date: markdownFile.frontmatter.date, fileName: filename, + tags: [], }); fileImports = [...fileImports, markdownFile]; @@ -199,6 +197,7 @@ export class MarkdownRepository { author: markdownFile.frontmatter?.author ?? undefined, date: markdownFile.frontmatter?.date ?? undefined, fileName: resolvedPath, + tags: [], }); return blogPost; diff --git a/src/lib/blog/test-builders/blog-post-builder.ts b/src/lib/blog/test-builders/blog-post-builder.ts index 4f15179..6164595 100644 --- a/src/lib/blog/test-builders/blog-post-builder.ts +++ b/src/lib/blog/test-builders/blog-post-builder.ts @@ -8,6 +8,7 @@ class BlogPostBuilder { private _date = new Date('2022-01-01T00:00Z'); private _slug = 'default-slug'; private _fileName = 'default-file-name.md'; + private _tags: string[] = []; withTitle(title: string): BlogPostBuilder { this._title = title; @@ -44,6 +45,16 @@ class BlogPostBuilder { return this; } + withTags(tags: string[]): BlogPostBuilder { + this._tags = tags; + return this; + } + + withEmptyTags(): BlogPostBuilder { + this._tags = []; + return this; + } + build(): BlogPost { return new BlogPost({ title: this._title, @@ -53,6 +64,7 @@ class BlogPostBuilder { slug: this._slug, fileName: this._fileName, excerpt: this._excerpt, + tags: this._tags, }); } }