Skip to content

Commit

Permalink
Exclude empty taxonomies, categories, and filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Oct 26, 2021
1 parent 215944e commit 4eae343
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
12 changes: 9 additions & 3 deletions dirmaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ def _make_taxonomies(self, item):
# Iterate through each taxonomy array in the entry.
for v in item[tx]:
if v not in out[tx]:
id = v.lower()
id = v.strip().lower()
if id == "":
continue

out[tx][id] = Taxonomy(
name=v, slug=self._make_slug(v), count=0)
for tx in self.config["taxonomies"]:

out[tx] = sorted([out[tx][v]
for v in out[tx]], key=lambda k: k.name)

Expand All @@ -164,7 +167,10 @@ def _collate_taxonomies(self, entries):
out[tx] = {}

for t in e.taxonomies[tx]:
id = t.name.lower()
id = t.name.strip().lower()
if id == "":
continue

if id not in out[tx]:
out[tx][id] = copy(t)
out[tx][id].count += 1
Expand Down
10 changes: 9 additions & 1 deletion dirmaker/example/static/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
function filterList(sel, itemSelector) {
const noRes = document.querySelector("#no-results");
// Hide all items.
document.querySelectorAll(itemSelector).forEach(e => {
e.style.display = "none";
});

if (sel.length === 0) {
noRes.style.display = 'block';
return;
}
noRes.style.display = 'none';

// List of attribute selector queries for each value. eg:
// #items li[data-language*=malayalam|], #items li[data-language*=kannada|] ...
Expand Down Expand Up @@ -102,7 +105,12 @@ function tokenize(str) {

// Check or uncheck all filter checkboxes with the toggle item's dataset.taxonomy.
const tax = e.target.dataset.taxonomy;
document.querySelectorAll(`#filters input[data-taxonomy=${tax}]`).forEach(el => {
const filters = document.querySelectorAll(`#filters input[data-taxonomy=${tax}]`);
if (filters.length === 0) {
return;
}

filters.forEach(el => {
el.checked = e.target.dataset.state === "on" ? false : true;
});

Expand Down
4 changes: 4 additions & 0 deletions dirmaker/example/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ footer {
display: inline-block !important;
}

#no-results {
display: none;
margin-top: 30px;
}

.pagination {
margin-top: 30px;
Expand Down
2 changes: 2 additions & 0 deletions dirmaker/example/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ <h2 class="title">
</ul>
{% endif %}
</section>

<h3 id="no-results">No results.</h3>
</section><!-- content -->
</div><!-- container -->

Expand Down

0 comments on commit 4eae343

Please sign in to comment.