From f258f0becb761d18d25905ad6ea66523eb942fca Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Thu, 30 Nov 2017 01:54:19 +0100 Subject: [PATCH] Fixing stuff --- .eslintrc | 11 ++++ .pre-commit-config.yaml | 6 ++ Makefile | 14 ++--- README.md | 6 +- templates/js/enable-search.js | 18 +++--- templates/js/filter-tags.js | 112 +++++++++++++++++----------------- templates/js/social.js | 6 +- test_ludochaordic.sh | 14 ++++- 8 files changed, 106 insertions(+), 81 deletions(-) create mode 100755 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100755 index 0000000..3f0e627 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": ["strict"], + "globals": { + "document": false, + "window": false, + "$": false + }, + "rules": { + "no-undefined": 0 + } +} \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cf96743..81550b2 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,3 +31,9 @@ - "--ignore=Bad value \"DUMMY\" for attribute \"type\" on element \"link\": Subtype missing" files: ^templates/[^/]*\.html$ exclude: ^templates/(index|tipue_search)\.html$ +- repo: local + hooks: + - id: make-eslint + language: system + entry: make eslint + files: '' diff --git a/Makefile b/Makefile index ced1b70..83560dd 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,17 @@ # BEWARE ! Makefiles require the use of hard tabs -NODE_BIN := node_modules/.bin - -.PHONY: install check test +.PHONY: install check lint test install: - npm install csslint eslint eslint-config-strict eslint-plugin-filenames htmlhint htmllint-cli jscs + npm install -g csslint eslint eslint-config-strict eslint-plugin-filenames htmlhint htmllint-cli lighthouse pip install pre-commit pre-commit install -check: - $(NODE_BIN)/eslint $(git ls-files [ grep '\.js$') - $(NODE_BIN)/jscs $(git ls-files [ grep '\.js$') - $(NODE_BIN)/csslint --ignore=order-alphabetical $(git ls-files [ grep '\.css$') +check: eslint pre-commit run --all-files +eslint: + eslint templates/js/*.js + test: ./test_ludochaordic.sh diff --git a/README.md b/README.md index 81aa5bf..5bfb05f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ -mg -============== +pelican-mg +========== + +[![Build Status](https://travis-ci.org/Lucas-C/pelican-mg.svg?branch=master)](https://travis-ci.org/Lucas-C/pelican-mg) A minimal theme for [Pelican](http://blog.getpelican.com/) that uses uikit. The theme is suited for a single author blog. Feeds are provided via ATOM. diff --git a/templates/js/enable-search.js b/templates/js/enable-search.js index 8f9b54f..c6c71c0 100644 --- a/templates/js/enable-search.js +++ b/templates/js/enable-search.js @@ -1,10 +1,10 @@ -$(document).ready(function() { - $('.tipue_search').tipuesearch({ - 'show': 10, - 'mode': 'json', - 'showURL': false, - 'descriptiveWords': 75, - 'highlightEveryTerm': true, - 'contentLocation': './tipue_search.json' - }); +$(document).ready(() => { + $('.tipue_search').tipuesearch({ + show: 10, + mode: 'json', + showURL: false, + descriptiveWords: 75, + highlightEveryTerm: true, + contentLocation: './tipue_search.json', + }); }); diff --git a/templates/js/filter-tags.js b/templates/js/filter-tags.js index 4b8c2b5..a828e3f 100644 --- a/templates/js/filter-tags.js +++ b/templates/js/filter-tags.js @@ -4,75 +4,73 @@ * - true => select ONLY articles with this tag * - false => do NOT select articles with this tag * */ -window.tagFilters = {} +(function iife() { + 'strict'; -function indexOf(array, predicate) { - for (var i = 0; i < array.length; i++) if (predicate(array[i])) return array[i]; -} -function includes(array, value) { - return array.indexOf(value) !== -1; -}; + window.tagFilters = {}; -function toggleTagFilter(tag) { - var filterState = window.tagFilters[tag] + function includes(anArray, value) { + return anArray.indexOf(value) >= 0; + } + + function updateArticlesVisibility() { + const includeFilters = Object.keys(window.tagFilters).filter((tagFilter) => window.tagFilters[tagFilter] === true); + const excludeFilters = Object.keys(window.tagFilters).filter((tagFilter) => window.tagFilters[tagFilter] === false); + Array.prototype.slice.call(document.getElementsByTagName('article')).forEach((article) => { + // article-excerpt: we ignore it + if (!article.dataset.tags) { + return; + } + const articleTags = JSON.parse(article.dataset.tags); + const allIncludeTags = includeFilters.every((tag) => includes(articleTags, tag)); + const anyExcludeTag = excludeFilters.some((tag) => includes(articleTags, tag)); + + // Now implementing the core logic + let shouldDisplay = !anyExcludeTag; + if (shouldDisplay && includeFilters.length > 0) { + shouldDisplay = allIncludeTags; + } + + if (shouldDisplay) { + article.classList.remove('mg-faded'); + } else { + article.classList.add('mg-faded'); + } + }); + } + + window.toggleTagFilter = function toggleTagFilter(tag) { + let filterState = window.tagFilters[tag]; if (filterState === true) { - this.classList.remove('mg-tag-filter-include'); - filterState = false; - this.classList.add('mg-tag-filter-exclude'); - this.title = 'Tag filter (exclude matching articles)'; + this.classList.remove('mg-tag-filter-include'); + filterState = false; + this.classList.add('mg-tag-filter-exclude'); + this.title = 'Tag filter (exclude matching articles)'; } else if (filterState === false) { - this.classList.remove('mg-tag-filter-exclude'); - filterState = undefined; - this.title = 'Tag filter (disabled)'; + this.classList.remove('mg-tag-filter-exclude'); + filterState = undefined; + this.title = 'Tag filter (disabled)'; } else { - filterState = true; - this.classList.add('mg-tag-filter-include'); - this.title = 'Tag filter (include matching articles)'; + filterState = true; + this.classList.add('mg-tag-filter-include'); + this.title = 'Tag filter (include matching articles)'; } window.tagFilters[tag] = filterState; updateArticlesVisibility(); -} + }; -function toggleLangTagFilter(langs) { - var lang = this.textContent; - window.tagFilters['lang:'+lang] = undefined; + window.toggleLangTagFilter = function toggleLangTagFilter(langs) { + let lang = this.textContent; + window.tagFilters[`lang:${ lang }`] = undefined; lang = langs[langs.indexOf(lang) + 1]; if (typeof lang === 'undefined') { - lang = 'lang' - this.title = 'Language filter (disabled)'; + lang = 'lang'; + this.title = 'Language filter (disabled)'; } else { - window.tagFilters['lang:'+lang] = true; - this.title = 'Language filter (include only "' + lang + '" articles)'; + window.tagFilters[`lang:${ lang }`] = true; + this.title = `Language filter (include only "${ lang }" articles)`; } this.textContent = lang; updateArticlesVisibility(); -} - -function updateArticlesVisibility() { - var includeFilters = Object.keys(window.tagFilters).filter(function (tagFilter) { - return window.tagFilters[tagFilter] === true; - }); - var excludeFilters = Object.keys(window.tagFilters).filter(function (tagFilter) { - return window.tagFilters[tagFilter] === false; - }); - 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 allIncludeTags = includeFilters.every(function (tag) { return includes(articleTags, tag); }); - var anyExcludeTag = excludeFilters.some(function (tag) { return includes(articleTags, tag); }); - - // Now implementing the core logic - var shouldDisplay = !anyExcludeTag; - if (shouldDisplay && includeFilters.length > 0) { - shouldDisplay = allIncludeTags; - } - - if (shouldDisplay) { - article.classList.remove('mg-faded'); - } else { - article.classList.add('mg-faded'); - } - }); -} + }; +}()); diff --git a/templates/js/social.js b/templates/js/social.js index fc218d4..d9a4639 100644 --- a/templates/js/social.js +++ b/templates/js/social.js @@ -1,4 +1,4 @@ -$(document).ready(function() { - $('.mg-container-social').height($('article').height()); - $('#mg-panel-social').stick_in_parent({offset_top: 35}); +$(document).ready(() => { + $('.mg-container-social').height($('article').height()); + $('#mg-panel-social').stick_in_parent({ 'offset_top': 35 }); }); diff --git a/test_ludochaordic.sh b/test_ludochaordic.sh index dd2aecc..4650520 100755 --- a/test_ludochaordic.sh +++ b/test_ludochaordic.sh @@ -1,6 +1,10 @@ #!/bin/bash set -o pipefail -o errexit -o nounset -o xtrace +cd .. +git clone https://github.com/getpelican/pelican-plugins.git +git submodule update --init image_process representative_image tag_cloud + cd .. git clone https://github.com/Lucas-C/ludochaordic.git cd ludochaordic @@ -8,5 +12,11 @@ cd ludochaordic pip install pelican markdown beautifulsoup4 pillow make DEBUG=1 OUTPUTDIR=output devserver -node_modules/.bin/htmlhint output/ -node_modules/.bin/htmllint output/ +csslint --ignore=order-alphabetical output/theme/css/main.css + +htmlhint output/ +htmllint output/ + +make devserver +lighthouse http://localhost: +make stopserver