Add search for js-enabled browsers
This commit is contained in:
parent
555128c88b
commit
d090f61543
@ -75,7 +75,7 @@ aside {
|
|||||||
main {
|
main {
|
||||||
margin-bottom: 5rem;
|
margin-bottom: 5rem;
|
||||||
|
|
||||||
article h1 a { color: inherit }
|
article h2 a { color: inherit }
|
||||||
.info {
|
.info {
|
||||||
border-top: 1px solid #eee;
|
border-top: 1px solid #eee;
|
||||||
margin: 2em 0;
|
margin: 2em 0;
|
||||||
@ -131,6 +131,15 @@ main {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
border-radius: .3em;
|
border-radius: .3em;
|
||||||
}
|
}
|
||||||
|
input.search {
|
||||||
|
display: none; // Hide for non-js browsers
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid #bbb;
|
||||||
|
padding: .5em 1em;
|
||||||
|
margin: 1em 0;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
|
@ -24,5 +24,6 @@
|
|||||||
{{ macros::list_posts(section="posts", count=config.extra.latest_posts_count) }}
|
{{ macros::list_posts(section="posts", count=config.extra.latest_posts_count) }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</main>
|
</main>
|
||||||
|
{% block script %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
{% macro print_article(page) %}
|
{% macro print_article(page) %}
|
||||||
<article>
|
<article>
|
||||||
<h1><a href="{{ page.permalink }}">{{ page.title }}</a></h1>
|
<h2><a href="{{ page.permalink }}">{{ page.title }}</a></h2>
|
||||||
<p>{{ page.summary | safe }}</p>
|
<p>{{ page.summary | safe }}</p>
|
||||||
{{ self::page_info(page=page) }}
|
{{ self::page_info(page=page) }}
|
||||||
</article>
|
</article>
|
||||||
|
@ -6,5 +6,32 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ section.title }}</h1>
|
<h1>{{ section.title }}</h1>
|
||||||
|
<input id="search" class="search" type="text" placeholder="Search titles" oninput="filter_name(this.value)">
|
||||||
{{ macros::list_posts() }}
|
{{ macros::list_posts() }}
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
<script>
|
||||||
|
function filter_name(str)
|
||||||
|
{
|
||||||
|
str = str.toLowerCase();
|
||||||
|
if (str.length == 0) {
|
||||||
|
for (let i = 0; i < articles.length; i++) {
|
||||||
|
articles[i].style.display = "block";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < articles.length; i++) {
|
||||||
|
let name = articles[i].getElementsByTagName("h2")[0].innerHTML.toLowerCase();
|
||||||
|
if (!name.includes(str)) {
|
||||||
|
articles[i].style.display = "none";
|
||||||
|
} else {
|
||||||
|
articles[i].style.display = "block";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let articles = document.getElementsByTagName("article");
|
||||||
|
let search = document.getElementById("search");
|
||||||
|
search.style.display = "inline-block";
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user