mirror of
https://github.com/LukeSmithxyz/based.cooking.git
synced 2025-06-05 15:10:24 +01:00
Replace "style=display:none" with HTML data tags:
When storing metadata in an HTML node, you can use data attributes, which is more declarative, and doesn't require rendering an invisible node. See: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
This commit is contained in:
parent
550fdf24f2
commit
4f17b3d901
@ -35,8 +35,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
|
|
||||||
// for each recipe hide all but matched
|
// for each recipe hide all but matched
|
||||||
recipes.forEach(recipe => {
|
recipes.forEach(recipe => {
|
||||||
const recipeName = recipe.textContent.toLowerCase();
|
const searchString = `${recipe.textContent} ${recipe.dataset.tags}`.toLowerCase();
|
||||||
const isMatch = searchTerms.every(term => recipeName.includes(term));
|
const isMatch = searchTerms.every(term => searchString.includes(term));
|
||||||
|
|
||||||
recipe.hidden = !isMatch;
|
recipe.hidden = !isMatch;
|
||||||
recipe.classList.toggle("matched-recipe", hasFilter && isMatch);
|
recipe.classList.toggle("matched-recipe", hasFilter && isMatch);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<ul id=artlist>
|
<ul id=artlist>
|
||||||
{{range.Site.RegularPages}}
|
{{range.Site.RegularPages}}
|
||||||
<li><a href="{{.Permalink}}">{{.Title}}<span style="display:none">{{.Params.Tags}}</span></a></li>
|
<li data-tags="{{.Params.Tags}}"><a href="{{.Permalink}}">{{.Title}}</a></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user