mirror of
https://github.com/c0de-archive/pelican-mg.git
synced 2025-10-10 11:08:39 +00:00
Implementing tag filters
This commit is contained in:
10
templates/js/enable-search.js
Normal file
10
templates/js/enable-search.js
Normal file
@@ -0,0 +1,10 @@
|
||||
$(document).ready(function() {
|
||||
$('.tipue_search').tipuesearch({
|
||||
'show': 10,
|
||||
'mode': 'json',
|
||||
'showURL': false,
|
||||
'descriptiveWords': 75,
|
||||
'highlightEveryTerm': true,
|
||||
'contentLocation': './tipue_search.json'
|
||||
});
|
||||
});
|
46
templates/js/filter-tags.js
Normal file
46
templates/js/filter-tags.js
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Filters state can be one of:
|
||||
* - undefined => disabled
|
||||
* - true => select ONLY articles with this tag
|
||||
* - false => do NOT select articles with this tag
|
||||
* */
|
||||
window.tagFilters = {}
|
||||
|
||||
function toggleTagFilter(tag) {
|
||||
var filterState = window.tagFilters[tag]
|
||||
if (filterState === true) {
|
||||
filterState = false;
|
||||
} else if (filterState === false) {
|
||||
filterState = undefined;
|
||||
} else {
|
||||
filterState = true;
|
||||
}
|
||||
window.tagFilters[tag] = filterState;
|
||||
updateArticlesVisibility();
|
||||
}
|
||||
|
||||
function updateArticlesVisibility() {
|
||||
var anyTrueFilter = Object.keys(window.tagFilters).some(function (tagFilter) {
|
||||
return !!window.tagFilters[tagFilter];
|
||||
});
|
||||
Array.prototype.slice.call(document.getElementsByTagName('article')).forEach(function (article) {
|
||||
if (!article.dataset.tags) { // article-excerpt: we ignore it
|
||||
return;
|
||||
}
|
||||
var articleTags = JSON.parse(article.dataset.tags);
|
||||
var anyTagWhitelisted = articleTags.some(function (tag) { return window.tagFilters[tag] === true; });
|
||||
var anyTagBlacklisted = articleTags.some(function (tag) { return window.tagFilters[tag] === false; });
|
||||
|
||||
// Now implementing the core logic
|
||||
var shouldDisplay = !anyTagBlacklisted;
|
||||
if (shouldDisplay && anyTrueFilter) {
|
||||
shouldDisplay = anyTagWhitelisted;
|
||||
}
|
||||
|
||||
if (shouldDisplay) {
|
||||
article.classList.remove('uk-hidden');
|
||||
} else {
|
||||
article.classList.add('uk-hidden');
|
||||
}
|
||||
});
|
||||
}
|
4
templates/js/social.js
Normal file
4
templates/js/social.js
Normal file
@@ -0,0 +1,4 @@
|
||||
$(document).ready(function() {
|
||||
$('.mg-container-social').height($('article').height());
|
||||
$('#mg-panel-social').stick_in_parent({offset_top: 35});
|
||||
});
|
Reference in New Issue
Block a user