From 90a45f9729f131569889f52cf792007f23df3949 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 7 Jan 2017 00:59:01 -0500 Subject: tidy --- Makefile | 93 ++--------------------------------------------------- benchmark | 7 ---- bin/index | 61 ----------------------------------- bin/page | 12 ------- bin/write-atomic | 21 ------------ bin/write-ifchanged | 25 -------------- check.rb | 19 ----------- make | 20 ++++++++++++ 8 files changed, 23 insertions(+), 235 deletions(-) delete mode 100755 benchmark delete mode 100755 bin/index delete mode 100755 bin/page delete mode 100755 bin/write-atomic delete mode 100755 bin/write-ifchanged delete mode 100755 check.rb create mode 100755 make diff --git a/Makefile b/Makefile index 2307b64..352236b 100644 --- a/Makefile +++ b/Makefile @@ -1,91 +1,4 @@ -SHELL = bash -o pipefail +MAKEFLAGS += -j1 -RUBYLIB := $(realpath .)/lib$(if $(RUBYLIB),:$(RUBYLIB)) -export RUBYLIB - -# Usage: $(call patsubst,PATTERN1 PATTERN2...,REPLACEMENT,TEXT) -# -# Like $(patsubst), but takes multiple patterns that are all replaced -# with the same replacement. -patsubst-all = $(if $1,$(call patsubst-all,$(wordlist 2,$(words $1),$1),$2,$(patsubst $(firstword $1),$2,$3)),$3) - -# Which suffixes can we turn in to HTML? -html.suffixes = md org -# Find all source files with those suffixes -html.src = $(shell find src -type f \( -false $(foreach s,$(html.suffixes), -o -name '*.$s' ) \)) -# Translate the source filenames into output filenames -html.out = $(call patsubst-all,$(addprefix src/%.,$(html.suffixes)),out/%.html,$(html.src)) -html.dirs = $(sort $(patsubst src%,out%, \ - $(patsubst %/,%,$(dir $(html.src))) \ - $(shell find src -name index.yaml -printf '%h\n'))) -html.out += out/index.atom $(addsuffix /index.html,$(html.dirs)) - -all: $(html.out) out/main.css -.PHONY: all out/tags - -bin/page = bin/page bin/util.rb bin/pandoc.rb -bin/index = bin/index bin/util.rb bin/pandoc.rb - -out/%.html: src/%.md $(bin/page) bin/page.html.erb bin/write-atomic - @mkdir -p $(@D) - bin/page html $< | bin/write-atomic $@ -out/%.html: out/%.md $(bin/page) bin/page.html.erb bin/write-atomic - bin/page html $< | bin/write-atomic $@ - -out/%.html: src/%.org $(bin/page) bin/page.html.erb bin/write-atomic - @mkdir -p $(@D) - bin/page html $< | bin/write-atomic $@ -out/%.html: out/%.org $(bin/page) bin/page.html.erb bin/write-atomic - bin/page html $< | bin/write-atomic $@ - -out/%.css: src/%.scss - @mkdir -p $(@D) - scss --stdin < $< > $@ -out/%.css: out/%.scss - scss --stdin < $< > $@ - -index.all = $(filter-out %/ChangeLog.md %/index.md,$(html.src) $(shell find src -type f -name index.yaml)) -index.filter = $(filter-out %/index.yaml,$(filter $(@D)/% $(patsubst out%,src%,$(@D))/%,$1)) -index.cmd = bin/index $(patsubst .%,%,$(suffix $@)) $(@D) $(call index.filter,$^) | bin/write-atomic $@ -index.dep = $(bin/index) bin/index.$1.erb .var.index.all $(index.all) bin/write-atomic Makefile -out/index.md : $(call index.dep,md) - @mkdir -p $(@D) - $(index.cmd) -out/%/index.md : $(call index.dep,md) - @mkdir -p $(@D) - $(index.cmd) -out/index.atom : $(call index.dep,atom) - @mkdir -p $(@D) - $(index.cmd) -out/%/index.atom : $(call index.dep,atom) - @mkdir -p $(@D) - $(index.cmd) - -serve: serve-8000 -serve-%: all - dir=$$(mktemp -d -t) && trap 'fusermount -u "$$dir"; rmdir "$$dir"' EXIT && unionfs -o ro out:src "$$dir" && (cd "$$dir" && python3 -m http.server $*) -.PHONY: serve serve-% - -.var.%: FORCE bin/write-ifchanged - @printf '%s' $(call quote.shell,$($*)) | sed 's/^/#/' | bin/write-ifchanged $@ --include $(wildcard .var.*) - - -irb: - irb -.PHONY: irb - -check: - ./check.rb - -.PHONY: FORCE -.DELETE_ON_ERROR: -.SECONDARY: - -define nl - - -endef -# I put this as the last line in the file because it confuses Emacs syntax -# highlighting and makes the remainder of the file difficult to edit. -quote.shell = $(subst $(nl),'$$'\n'','$(subst ','\'',$1)') +%: + ./make diff --git a/benchmark b/benchmark deleted file mode 100755 index b06c621..0000000 --- a/benchmark +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -rm -rf out -thing='start up' -{ make -j1; echo done;}|ts -i '%.s'|sed 's/ .* / /' |while read -r time newthing; do - echo $time $thing - thing=$newthing -done | sort -n diff --git a/bin/index b/bin/index deleted file mode 100755 index c3ac2ff..0000000 --- a/bin/index +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: utf-8 -*- -require 'util' -require 'yaml' - -# ARGV[0] -type = ARGV.shift -template = "bin/index.#{type}.erb" -erb = ERB.new(File.read(template)); -erb.filename = template - -# ARGV[1] -@path = ARGV.shift -webpath = (@path+'/').sub(/^(src|out)\//, '/') -if type == 'atom' - webpath += 'index.atom' -end -@url = URI::parse('https://www.andrewdm.me/') + webpath - -indexyaml = @path.sub('out', 'src')+'/index.yaml' -if File.exists?(indexyaml) - metadata = YAML::load(File.read(indexyaml)) -else - metadata = {} -end - -@pages = [] -for data in metadata['external'] - @pages.push(ExternPage.new(data)) -end - -# ARGV[2..] -for filename in ARGV do - @pages.push(Page.new(filename)) -end - -# main -@title = metadata['title'] || @path.sub('out', '') - -def guess_section(page) - for path in @sections.keys do - if @url.route_to(page.url).to_s.start_with?(path+'/') - return path - end - end - return '' -end - -@sections = { '' => {'head' => '', 'body' => []} } -(metadata['sections'] || []).each do |path, name| - @sections[path] = { - 'head' => name, - 'body' => [] - } -end -for page in @pages do - section = page.section || guess_section(page) - @sections[section]['body'].push(page) -end - -erb.run() diff --git a/bin/page b/bin/page deleted file mode 100755 index e2d4f38..0000000 --- a/bin/page +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: utf-8 -*- -require 'util' -require 'uri' - -template = "bin/page.#{ARGV[0]}.erb" -@page = Page.new(ARGV[1]) -@url = URI::parse('https://www.andrewdm.me/') + @page.absoutpath - -erb = ERB.new(File.read(template)); -erb.filename = template -erb.run() diff --git a/bin/write-atomic b/bin/write-atomic deleted file mode 100755 index efb2551..0000000 --- a/bin/write-atomic +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2015-2016 Luke Shumaker -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -outfile=$1 -tmpfile="$(dirname "$outfile")/.tmp${outfile##*/}" - -cat > "$tmpfile" || { r=$?; rm -f "$tmpfile"; exit $r; } -mv -f "$tmpfile" "$outfile" diff --git a/bin/write-ifchanged b/bin/write-ifchanged deleted file mode 100755 index 185ceb0..0000000 --- a/bin/write-ifchanged +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2015 Luke Shumaker -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -outfile=$1 -tmpfile="$(dirname "$outfile")/.tmp${outfile##*/}" - -cat > "$tmpfile" || exit $? -if cmp -s "$tmpfile" "$outfile"; then - rm -f "$tmpfile" || : -else - mv -f "$tmpfile" "$outfile" -fi diff --git a/check.rb b/check.rb deleted file mode 100755 index 7126e25..0000000 --- a/check.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env ruby -require 'sitegen' -require 'page_index' - -# Initialize the site generator -Sitegen::init - -# This should trigger a full recursive crawl, loadng everything into -# the sitegen. -IndexPage::new('src').local_input - -# Tell the sitegen which files we want -Sitegen.pages.each do |page| - Sitegen::want(page.local_outfile) -end -Sitegen::want('out/index.atom') - -# Make! -print Sitegen::make(:all) diff --git a/make b/make new file mode 100755 index 0000000..b3090a3 --- /dev/null +++ b/make @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby +$:.unshift('lib') +require 'sitegen' +require 'page_index' + +# Initialize the site generator +Sitegen::init + +# This should trigger a full recursive crawl, loadng everything into +# the sitegen. +IndexPage::new('src').local_input + +# Tell the sitegen which files we want +Sitegen.pages.each do |page| + Sitegen::want(page.local_outfile) +end +Sitegen::want('out/index.atom') + +# Make! +print Sitegen::make(:all) -- cgit v1.2.3