blog

git clone https://git.ce9e.org/blog.git

commit
3627220a382a03e06d417951eb1a0d20f8c3ebc4
parent
1e13e5fcd5bdfc0a7cb1a85bf27e9c4130faa463
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-03-26 01:12
fix blogssearch

Diffstat

M _templates/base.html 12 ------------
M posts.sh 5 ++++-
M static/blogsearch.js 11 +++++------

3 files changed, 9 insertions, 19 deletions


diff --git a/_templates/base.html b/_templates/base.html

@@ -40,18 +40,6 @@ ${endfor}
   40    40 ${endif}
   41    41 
   42    42 		${^}${body}
   43    -1 
   44    -1 ${if(posts)}
   45    -1 		<ul class="blog">
   46    -1 ${for(posts)}
   47    -1 			<li class="blog__post" data-tags="${for(it.tags)}${it}${sep} ${endfor}">
   48    -1 				<a href="${it.url}">${it.title}</a>
   49    -1 			</li>
   50    -1 ${endfor}
   51    -1 		</ul>
   52    -1 
   53    -1 		<script src="/static/blogsearch.js" type="module"></script>
   54    -1 ${endif}
   55    43 	</main>
   56    44 </body>
   57    45 </html>

diff --git a/posts.sh b/posts.sh

@@ -16,5 +16,8 @@ ls _content/posts | tac | while read -r l; do
   16    16 	fi
   17    17 
   18    18 	yml="_content/posts/$l/index.md"
   19    -1 	echo "- [$(getyml 'title' "$yml")](/posts/$l/)"
   -1    19 	echo "- [$(getyml 'title' "$yml")](/posts/$l/){data-tags=\"$(getyml 'tags' "$yml" | sed 's/^\[\(.*\)\]$/\1/;s/, */ /g')\"}"
   20    20 done
   -1    21 
   -1    22 echo
   -1    23 echo '<script src="/static/blogsearch.js" type="module"></script>'

diff --git a/static/blogsearch.js b/static/blogsearch.js

@@ -1,11 +1,10 @@
    1    -1 var tag = location.hash.substr(1);
   -1     1 var tag = location.hash.substr(1).replaceAll('"', '');
    2     2 
    3     3 if (tag) {
    4    -1 	var blog = document.querySelector('.blog');
   -1     4 	var posts = document.querySelectorAll('[data-tags]');
    5     5 
    6    -1 	for (var i = 0; i < blog.children.length; i++) {
    7    -1 		var post = blog.children[i];
    8    -1 		var tags = post.dataset.tags.trim().split(/\s/);
    9    -1 		post.hidden = !tags.includes(tag);
   -1     6 	for (var i = 0; i < posts.length; i++) {
   -1     7 		var post = posts[i];
   -1     8 		post.closest('li').hidden = !post.matches(`[data-tags~="${tag}"]`);
   10     9 	}
   11    10 }