~sircmpwn/core.sr.ht

a2b0a05b6508a98d4548ebfa4f57da69cca27503 — Drew DeVault 4 years ago 885c3e6
Add static assets Makefile and uber-minification
5 files changed, 70 insertions(+), 2 deletions(-)

M .gitignore
A Makefile
A minify-css.js
A package.json
M templates/layout.html
M .gitignore => .gitignore +1 -0
@@ 7,3 7,4 @@ lib/
*.rdb
pip-selfcheck.json
.sass-cache/
node_modules

A Makefile => Makefile +43 -0
@@ 0,0 1,43 @@
# Run `make` to compile static assets
# Run `make watch` to recompile whenever a change is made

.PHONY: all static watch clean

SCRIPTS+=$(patsubst js/%.js,static/%.js,$(wildcard js/*.js))
_STATIC:=$(patsubst _static/%,static/%,$(wildcard _static/*))

SRHT_PATH?=/usr/lib/python3.6/site-packages/srht

static/%: _static/%
	@mkdir -p static/
	cp $< $@

static/main.css: scss/*.scss ${SRHT_PATH}/scss/*.scss
	@mkdir -p static/
	sassc -I${SRHT_PATH}/scss scss/main.scss $@

static/main.min.css: static/main.css
	node ${SRHT_PATH}/minify-css.js \
		static/main.css \
		static/main.min.css \
		"templates/*" "${SRHT_PATH}/templates/*"

static/%.js: js/%.js
	@mkdir -p static/
	cp $< $@

static: $(SCRIPTS) $(_STATIC) static/main.min.css

all: static

clean:
	rm -rf static

watch:
	while inotifywait \
		-e close_write js/ \
		-e close_write scss/ \
		-e close_write _static/; \
		do make; done

.DEFAULT_GOAL=all

A minify-css.js => minify-css.js +15 -0
@@ 0,0 1,15 @@
var purify = require('purify-css');

var input = process.argv[2];
var output = process.argv[3];
var files = [];

for (var i = 4; i < process.argv.length; ++i) {
  files.push(process.argv[i]);
}

purify(files, [input], {
  minify: true,
  output: output,
  whitelist: ["*cgit*"],
});

A package.json => package.json +10 -0
@@ 0,0 1,10 @@
{
  "name": "srht",
  "version": "1.0.0",
  "description": "Dummy package for build deps",
  "author": "Drew DeVault <sir@cmpwn.com>",
  "license": "GPL-2.0",
  "dependencies": {
    "purify-css": "^1.1.9"
  }
}

M templates/layout.html => templates/layout.html +1 -2
@@ 4,8 4,7 @@
    {% block title %}
    <title>sr.ht {{site}}</title>
    {% endblock %}
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
    <link rel="stylesheet" href="/static/main.css">
    <link rel="stylesheet" href="/static/main.min.css">
  </head>
  <body>
    {% block nav %}