Last active
November 17, 2019 05:24
-
-
Save Kiwi/68ce89a0bd92d1e667f88880fd5a7214 to your computer and use it in GitHub Desktop.
my hakyll build/development/deploy/make scripts. replacement `watch` uses inotify to run purifycss which removes unused rules and minifies into one file, which makes the site load much faster, `deploy` uploads to github pages. can also run `hindent` manually for kicks. an html-tidy compiler filter makes sure the html format is good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat bin/ | |
checkimports deploy hindent hoogle purify purify.js watch | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat bin/hindent | |
#!/bin/sh | |
SCRIPT=$(realpath "$0") | |
SCRIPTPATH=$(dirname "$SCRIPT") | |
SOURCEPATH="$(cd "$SCRIPTPATH"/../src && pwd)" | |
for i in "$SOURCEPATH"/*.hs "$SOURCEPATH"/*/*.hs; do | |
hindent --validate "$i"; | |
hindent "$i"; | |
done | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat bin/purify | |
#!/bin/sh | |
SCRIPT=$(realpath "$0") | |
SCRIPTPATH=$(dirname "$SCRIPT") | |
cd "$SCRIPTPATH" || exit | |
node purify.js | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat bin/purify.js | |
const purify = require("purifycss"); | |
var content = [ | |
"**/../_site/js/*.js", | |
"**/../_site/**/*.html", | |
"**/../_site/fonts/*.otf" | |
]; | |
var css = [ | |
"**/../provider/assets/css/bootstrap.css", | |
"**/../provider/assets/css/tango.css", | |
"**/../provider/assets/css/custom.css" | |
]; | |
var options = { | |
output: "../provider/assets/css/purifiedcss.css", | |
// Will minify CSS code in addition to purify. | |
minify: true, | |
// Logs out removed selectors. | |
rejected: false, | |
info: true | |
}; | |
purify(content, css, options); | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat bin/watch | |
#!/bin/sh | |
SCRIPT="$(realpath "$0")" | |
SCRIPTPATH="$(dirname "$SCRIPT")" | |
ROOTPATH="$(cd "$SCRIPTPATH"/../ && pwd)" | |
cd "$ROOTPATH" || exit 1 | |
cabal v1-run site server & | |
make watchprovider | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat bin/deploy | |
#!/bin/sh | |
SCRIPT="$(realpath "$0")" | |
SCRIPTPATH="$(dirname "$SCRIPT")" | |
ROOTPATH="$(cd "$SCRIPTPATH"/../ && pwd)" | |
SITEPATH="$(cd "$SCRIPTPATH"/../mostlyabsurd.github.io && pwd)" | |
cd "$SITEPATH" || exit 1 | |
git pull origin master | |
git checkout master | |
# Overwrite existing files with new files | |
rsync -a --filter='P _site/' \ | |
--filter='P _cache/' \ | |
--filter='P .git/' \ | |
--filter='P .gitignore' \ | |
--delete-excluded \ | |
.git .gitignore ../_site/ . | |
cp robots.txt robots-mostlyabsurd-com.txt | |
cp sitemap.xml sitemap-mostlyabsurd-com.xml | |
sed -i 's:mostlyabsurd.github.io:mostlyabsurd.com:g' robots-mostlyabsurd-com.txt | |
sed -i 's:mostlyabsurd.github.io:mostlyabsurd.com:g' sitemap-mostlyabsurd-com.xml | |
cp robots.txt robots-myfriendshate-me.txt | |
cp sitemap.xml sitemap-myfriendshate-me.xml | |
sed -i 's:mostlyabsurd.github.io:myfriendshate.me:g' robots-myfriendshate-me.txt | |
sed -i 's:mostlyabsurd.github.io:myfriendshate.me:g' sitemap-myfriendshate-me.xml | |
# Commit | |
git add -A | |
git commit --amend --reset-author -m "Publish." | |
# Push | |
git push origin master --force | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat Makefile | |
.PHONY: build purifycss deploy main hindent watch | |
main: purifycss | |
purifycss: build | |
cabal v1-run site rebuild | |
bin/purify | |
cabal v1-run site rebuild | |
build: | |
cabal v1-configure | |
cabal v1-build | |
clean: | |
cabal v1-run site clean | |
cabal new-clean | |
cabal v1-clean | |
deploy: main | |
bash bin/deploy | |
hindent: | |
bin/hindent | |
watch: | |
bin/watch | |
# https://sillybytes.net/posts/using_hakyll_with_cassius.html | |
watchprovider: | |
while true; do make; inotifywait --exclude=\.*\.swp -qre modify provider src; done | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat shell.nix | |
{ nixpkgs ? (import (fetchTarball "https://releases.nixos.org/nixos/unstable/nixos-19.09pre186857.239fffc90d7/nixexprs.tar.xz") {}), compiler ? "ghc865" }: | |
#{ nixpkgs ? (import (fetchTarball "channel:nixos-unstable") {}), compiler ? "ghc865" }: | |
#{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc865" }: | |
let | |
inherit (nixpkgs) pkgs; | |
ghc = pkgs.haskell.packages.${compiler}.ghcWithHoogle (ps: with ps; [ | |
hakyll | |
####### | |
ghcid | |
hindent | |
hlint | |
shake | |
####### | |
blaze-html | |
bytestring | |
containers | |
filepath | |
pandoc | |
pandoc-types | |
unordered-containers | |
pandoc-include-code | |
split | |
text | |
time | |
]); | |
purifycss = (import ./nix/purifycss { }).purifycss; | |
prettier = (import ./nix/prettier { }).prettier; | |
in | |
pkgs.stdenv.mkDerivation { | |
name = "www-mostlyabsurd-com"; | |
buildInputs = with pkgs; [ | |
cabal-install | |
ghc | |
html-tidy | |
inotifyTools | |
nodePackages.npm | |
nodejs | |
prettier | |
purifycss | |
sass | |
zlib | |
which | |
]; | |
shellHook = '' | |
eval $(egrep ^export ${ghc}/bin/ghc) | |
export HIE_HOOGLE_DATABASE="$(cat $(which hoogle) | sed -n -e 's|.*--database \(.*\.hoo\).*|\1|p')" | |
''; | |
} | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat nix/purifycss/ | |
default.nix node-env.nix node-packages.json node-packages.nix | |
[kiwi@mvp-nixos www.mostlyabsurd.com]$ cat nix/purifycss/node-packages.json | |
[ "purifycss" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment