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`,
|
fileName: `the-file-name.md`,
|
||||||
html: 'Test Content',
|
html: 'Test Content',
|
||||||
excerpt: 'Test Excerpt',
|
excerpt: 'Test Excerpt',
|
||||||
|
tags: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
|
|
@ -25,6 +26,7 @@ describe('BlogPost', () => {
|
||||||
.withHtml('Test Content')
|
.withHtml('Test Content')
|
||||||
.withExcerpt('Test Excerpt')
|
.withExcerpt('Test Excerpt')
|
||||||
.withFileName(`the-file-name.md`)
|
.withFileName(`the-file-name.md`)
|
||||||
|
.withEmptyTags()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
expect(blogPost).toStrictEqual(expectedBlogPost);
|
expect(blogPost).toStrictEqual(expectedBlogPost);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ interface BlogPostParams {
|
||||||
fileName: string; // excluding any leading `..`
|
fileName: string; // excluding any leading `..`
|
||||||
html: string;
|
html: string;
|
||||||
excerpt: string;
|
excerpt: string;
|
||||||
|
tags: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BlogPost {
|
export class BlogPost {
|
||||||
|
|
@ -16,6 +17,7 @@ export class BlogPost {
|
||||||
readonly fileName: string;
|
readonly fileName: string;
|
||||||
public readonly html: string;
|
public readonly html: string;
|
||||||
public readonly excerpt: string;
|
public readonly excerpt: string;
|
||||||
|
public readonly tags: string[] = [];
|
||||||
|
|
||||||
constructor(params: BlogPostParams) {
|
constructor(params: BlogPostParams) {
|
||||||
this.title = params.title;
|
this.title = params.title;
|
||||||
|
|
@ -25,5 +27,6 @@ export class BlogPost {
|
||||||
this.fileName = params.fileName.split(`/`)[-1];
|
this.fileName = params.fileName.split(`/`)[-1];
|
||||||
this.html = params.html;
|
this.html = params.html;
|
||||||
this.excerpt = params.excerpt;
|
this.excerpt = params.excerpt;
|
||||||
|
this.tags = params.tags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,12 @@ import { BookReviewSet } from './BookReviewSet.js';
|
||||||
import { BookReview } from './BookReview.js';
|
import { BookReview } from './BookReview.js';
|
||||||
import { SnoutStreetStudiosPost } from '$lib/snout-street-studios/SnoutStreetStudiosPost.js';
|
import { SnoutStreetStudiosPost } from '$lib/snout-street-studios/SnoutStreetStudiosPost.js';
|
||||||
import { SnoutStreetStudiosPostSet } from './SnoutStreetStudiosPostSet.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,
|
// We have to duplicate the `../..` here because import.meta must have a static string,
|
||||||
// and it (rightfully) cannot have dynamic locations
|
// and it (rightfully) cannot have dynamic locations
|
||||||
const blogPostMetaGlobImport = import.meta.glob(`../../content/blog/*.md`, { as: 'raw' });
|
const blogPostMetaGlobImport = import.meta.glob(`../../content/blog/*.md`, { as: 'raw' });
|
||||||
const bookReviewsMetaGlobImport = import.meta.glob(`../../content/book-reviews/*.md`, { as: 'raw' });
|
const bookReviewsMetaGlobImport = import.meta.glob(`../../content/book-reviews/*.md`, { as: 'raw' });
|
||||||
const snoutStreetStudiosPostMetaGlobImport = import.meta.glob('../../content/snout-street-studios/*.md', {
|
const snoutStreetStudiosPostMetaGlobImport = import.meta.glob('../../content/snout-street-studios/*.md', { as: 'raw' });
|
||||||
as: 'raw',
|
|
||||||
});
|
|
||||||
|
|
||||||
interface BlogPostFrontmatterValues {
|
interface BlogPostFrontmatterValues {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -93,6 +90,7 @@ export class MarkdownRepository {
|
||||||
author: markdownFile.frontmatter.author,
|
author: markdownFile.frontmatter.author,
|
||||||
date: markdownFile.frontmatter.date,
|
date: markdownFile.frontmatter.date,
|
||||||
fileName: filename,
|
fileName: filename,
|
||||||
|
tags: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
fileImports = [...fileImports, markdownFile];
|
fileImports = [...fileImports, markdownFile];
|
||||||
|
|
@ -199,6 +197,7 @@ export class MarkdownRepository {
|
||||||
author: markdownFile.frontmatter?.author ?? undefined,
|
author: markdownFile.frontmatter?.author ?? undefined,
|
||||||
date: markdownFile.frontmatter?.date ?? undefined,
|
date: markdownFile.frontmatter?.date ?? undefined,
|
||||||
fileName: resolvedPath,
|
fileName: resolvedPath,
|
||||||
|
tags: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
return blogPost;
|
return blogPost;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ class BlogPostBuilder {
|
||||||
private _date = new Date('2022-01-01T00:00Z');
|
private _date = new Date('2022-01-01T00:00Z');
|
||||||
private _slug = 'default-slug';
|
private _slug = 'default-slug';
|
||||||
private _fileName = 'default-file-name.md';
|
private _fileName = 'default-file-name.md';
|
||||||
|
private _tags: string[] = [];
|
||||||
|
|
||||||
withTitle(title: string): BlogPostBuilder {
|
withTitle(title: string): BlogPostBuilder {
|
||||||
this._title = title;
|
this._title = title;
|
||||||
|
|
@ -44,6 +45,16 @@ class BlogPostBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withTags(tags: string[]): BlogPostBuilder {
|
||||||
|
this._tags = tags;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
withEmptyTags(): BlogPostBuilder {
|
||||||
|
this._tags = [];
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
build(): BlogPost {
|
build(): BlogPost {
|
||||||
return new BlogPost({
|
return new BlogPost({
|
||||||
title: this._title,
|
title: this._title,
|
||||||
|
|
@ -53,6 +64,7 @@ class BlogPostBuilder {
|
||||||
slug: this._slug,
|
slug: this._slug,
|
||||||
fileName: this._fileName,
|
fileName: this._fileName,
|
||||||
excerpt: this._excerpt,
|
excerpt: this._excerpt,
|
||||||
|
tags: this._tags,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue