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 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to '_posts') 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')); -- cgit v1.2.1