summaryrefslogtreecommitdiff
path: root/_posts
diff options
context:
space:
mode:
authormattkae <mattkae@protonmail.com>2022-11-13 20:07:38 -0500
committermattkae <mattkae@protonmail.com>2022-11-13 20:07:38 -0500
commit3ca36d468d1d1fb2aab4f0ed889cd46849d6c272 (patch)
treecbd054c6ae2ea311da12f2dd0ec809611d5b456b /_posts
parentf75dfb5d736b644ad2649452c3056ba71be856b8 (diff)
Per tag filter page
Diffstat (limited to '_posts')
-rw-r--r--_posts/processPosts.js30
1 files changed, 24 insertions, 6 deletions
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 `
- <button id="${tag.id}">${tag.title}</button>
+ <a href="${createTagFile(tag)}"><button id="${tag.id}">${tag.title}</button></a>
`;
}
@@ -77,7 +90,8 @@ function createPostLink(post) {
`;
}
-const output = `
+function createPostPage(outputFile, postFilter) {
+ const output = `
<!DOCTYPE html>
<html lang="en">
<head>
@@ -101,21 +115,25 @@ const output = `
</nav>
</header>
- <section>
+ ${postFilter ? '' : `<section>
<h2>Tags</h2>
+
<div id='tag_list'>
${tags.map(createTag)}
</div>
- </section
+ </section`}
<section>
<h2>Posts</h2>
<ul id='post_list'>
- ${posts.map(createPostLink)}
+ ${posts.filter(post => !postFilter || post.tags.includes(postFilter)).map(createPostLink)}
</ul>
</section>
</body>
</html>
`
-fs.writeFileSync(path.join(__dirname, '..', 'posts.html'), output);
+ fs.writeFileSync(outputFile, output);
+}
+
+createPostPage(path.join(__dirname, '..', 'posts.html'));