feat: add the tags property to the BlogPost item
This commit is contained in:
parent
0c64e015d1
commit
cf5e77b00b
4 changed files with 20 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue