From 3ca36d468d1d1fb2aab4f0ed889cd46849d6c272 Mon Sep 17 00:00:00 2001 From: mattkae Date: Sun, 13 Nov 2022 20:07:38 -0500 Subject: Per tag filter page --- _posts/processPosts.js | 30 ++++++++++++++++++++++++------ posts.html | 5 +++-- posts/tag_[object Object].html | 36 ++++++++++++++++++++++++++++++++++++ posts/tag_personal.html | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 posts/tag_[object Object].html create mode 100644 posts/tag_personal.html diff --git a/_posts/processPosts.js b/_posts/processPosts.js index 9db4103..55c97df 100644 --- a/_posts/processPosts.js +++ b/_posts/processPosts.js @@ -18,9 +18,22 @@ const posts = [ } ]; +function createTagFile(tag) { + const dir = path.resolve(path.join(__dirname, '..', 'posts')); + + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + + + const tagFileName = `tag_${tag.id}.html` + createPostPage(path.join(__dirname, '..', 'posts', tagFileName), tag.id) + return `/posts/${tagFileName}`; +} + function createTag(tag) { return ` - + `; } @@ -77,7 +90,8 @@ function createPostLink(post) { `; } -const output = ` +function createPostPage(outputFile, postFilter) { + const output = ` @@ -101,21 +115,25 @@ const output = ` -
+ ${postFilter ? '' : `

Tags

+
${tags.map(createTag)}
-

Posts

` -fs.writeFileSync(path.join(__dirname, '..', 'posts.html'), output); + fs.writeFileSync(outputFile, output); +} + +createPostPage(path.join(__dirname, '..', 'posts.html')); diff --git a/posts.html b/posts.html index 777073c..3f75430 100644 --- a/posts.html +++ b/posts.html @@ -24,12 +24,13 @@

Tags

+
- +
-

Posts

diff --git a/posts/tag_[object Object].html b/posts/tag_[object Object].html new file mode 100644 index 0000000..1999d78 --- /dev/null +++ b/posts/tag_[object Object].html @@ -0,0 +1,36 @@ + + + + + + + + + Matthew Kosarek + + + +
+

Matthew Kosarek

+ +
+ + + +
+

Posts

+ +
+ + diff --git a/posts/tag_personal.html b/posts/tag_personal.html new file mode 100644 index 0000000..1999d78 --- /dev/null +++ b/posts/tag_personal.html @@ -0,0 +1,36 @@ + + + + + + + + + Matthew Kosarek + + + +
+

Matthew Kosarek

+ +
+ + + +
+

Posts

+ +
+ + -- cgit v1.2.1