From 9a00ee06b77c4b984adc5250d9305250fe4df03c Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Sun, 3 Dec 2017 00:59:03 +0100 Subject: [PATCH] Fixing tests & getting rid of Makefile --- .pre-commit-config.yaml | 3 +-- .travis.yml | 6 +++--- Makefile | 17 ----------------- README.md | 2 +- gen_imgs_from_mds.py | 31 +++++++++++++++++++++++++++++++ run.sh | 38 ++++++++++++++++++++++++++++++++++++++ test_ludochaordic.sh | 26 -------------------------- 7 files changed, 74 insertions(+), 49 deletions(-) delete mode 100644 Makefile create mode 100755 gen_imgs_from_mds.py create mode 100755 run.sh delete mode 100755 test_ludochaordic.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fdfdb9b..b4e7d09 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,12 +9,11 @@ sha: v1.1.4 hooks: - id: remove-crlf - exclude: npp/.*\.xml - id: remove-tabs - repo: local hooks: - id: eslint name: eslint language: system - entry: make eslint + entry: sh -c 'eslint templates/js/*.js' files: '' diff --git a/.travis.yml b/.travis.yml index 053efe6..0cbe93c 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: 3.5 -install: make install +install: ./run.sh install script: - - make check - - make test + - pre-commit run --all-files + - ./run.sh test_ludochaordic diff --git a/Makefile b/Makefile deleted file mode 100644 index 83560dd..0000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# BEWARE ! Makefiles require the use of hard tabs - -.PHONY: install check lint test - -install: - npm install -g csslint eslint eslint-config-strict eslint-plugin-filenames htmlhint htmllint-cli lighthouse - pip install pre-commit - pre-commit install - -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 5bfb05f..be639ca 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Features * Analytics with Google Analytics, PIWIK and StatCounter. * Share buttons built with share urls. * Custom footer notice. -* W3C-Validatated HTML +* W3C-Validated HTML Install ------- diff --git a/gen_imgs_from_mds.py b/gen_imgs_from_mds.py new file mode 100755 index 0000000..fb27f80 --- /dev/null +++ b/gen_imgs_from_mds.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import html5lib, os, sys +from markdown import markdown + +SMALLEST_JPG = b'\xff\xd8\xff\xdb\x00C\x00\x03\x02\x02\x02\x02\x02\x03\x02\x02\x02\x03\x03\x03\x03\x04\x06\x04\x04\x04\x04\x04\x08\x06\x06\x05\x06\t\x08\n\n\t\x08\t\t\n\x0c\x0f\x0c\n\x0b\x0e\x0b\t\t\r\x11\r\x0e\x0f\x10\x10\x11\x10\n\x0c\x12\x13\x12\x10\x13\x0f\x10\x10\x10\xff\xc9\x00\x0b\x08\x00\x01\x00\x01\x01\x01\x11\x00\xff\xcc\x00\x06\x00\x10\x10\x05\xff\xda\x00\x08\x01\x01\x00\x00?\x00\xd2\xcf \xff\xd9' + +SMALLEST_PNG = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01\x00\x00\x05\x00\x01\r\n-\xb4\x00\x00\x00\x00IEND\xaeB`\x82' + +SMALLEST_GIF = b'GIF89a\x01\x00\x01\x00\x80\x00\x00\xff\xff\xff\x00\x00\x00!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;' + +for md_file_path in sys.argv[1:]: + with open(md_file_path) as md_file: + md_content = md_file.read() + html = markdown(md_content) + doc_root = html5lib.parse(html) + for img in doc_root.iter('{http://www.w3.org/1999/xhtml}img'): + img_url = img.attrib['src'] + if img_url.startswith('http'): + continue + os.makedirs(os.path.dirname(img_url), exist_ok=True) + if img_url.lower().endswith('jpg') or img_url.lower().endswith('jpeg'): + with open(img_url, 'wb') as img_file: + img_file.write(SMALLEST_JPG) + elif img_url.lower().endswith('png'): + with open(img_url, 'wb') as img_file: + img_file.write(SMALLEST_PNG) + elif img_url.lower().endswith('gif'): + with open(img_url, 'wb') as img_file: + img_file.write(SMALLEST_GIF) + else: + print('Unknown image type:', img_url) diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..2698dca --- /dev/null +++ b/run.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# USAGE: ./run.sh ( install | test_ludochaordicn ) + +set -o pipefail -o errexit -o nounset -o xtrace + +install () { + npm install -g csslint eslint eslint-config-strict eslint-plugin-filenames htmlhint htmllint-cli lighthouse + pip install html5validator pre-commit + pre-commit install +} + +test_ludochaordic () { + cd .. + git clone https://github.com/getpelican/pelican-plugins.git + cd pelican-plugins + git submodule update --init image_process representative_image tag_cloud + + cd .. + git clone https://github.com/Lucas-C/ludochaordic.git + cd ludochaordic + + pip install pelican markdown beautifulsoup4 pillow html5lib + ../gen_imgs_from_mds.py *.md + make DEBUG=1 OUTPUTDIR=output html + + csslint --ignore=order-alphabetical output/theme/css/main.css + + html5validator --root output/ + htmlhint output/ + htmllint output/ + + make devserver + lighthouse http://localhost: + make stopserver +} + +eval "$1" diff --git a/test_ludochaordic.sh b/test_ludochaordic.sh deleted file mode 100755 index b6ef0fc..0000000 --- a/test_ludochaordic.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -set -o pipefail -o errexit -o nounset -o xtrace - -cd .. -git clone https://github.com/getpelican/pelican-plugins.git -cd pelican-plugins -git submodule update --init image_process representative_image tag_cloud - -cd .. -git clone https://github.com/Lucas-C/ludochaordic.git -cd ludochaordic - -pip install pelican markdown beautifulsoup4 pillow -make DEBUG=1 OUTPUTDIR=output html -# crash HERE because of missing imgs -> TODO: -# - ./list_imgs_from_mds.py *.md -> currently incaple to extract img from content/2015-07-24-youtube_playlist_watcher -# - create dummy jpg / png / gif files for each - -csslint --ignore=order-alphabetical output/theme/css/main.css - -htmlhint output/ -htmllint output/ - -make devserver -lighthouse http://localhost: -make stopserver