summaryrefslogtreecommitdiff
path: root/publish.sh
blob: c3f8d33e5725baeae0eb6496b6cd52856b824202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
set -x

cd $(dirname $0)
git --work-tree=input --git-dir=/storage/projects/org.git checkout -f

INPUTS=$(find input -name '*.org' -exec grep -l "#+PUBLISH" {} \;)
readonly filter='s/#\+PUBLISH//g; ;s/\[file:([^\]]*)\.org\]/[file:$1.html]/g'

mkdir -p www
cp static/*.css www

for input in ${INPUTS}; do
    output="www${input#input}"
    output="${output%org}html"
    mkdir -p $(dirname "$output")
    perl -pe "$filter" "$input" | pandoc -f org -s -t html5 -H static/header-ext.html -o "$output"
done

mkdir -p www/images
IMAGES=$(find input -regextype awk -iregex '.*\.(jpg|png)')
for image in ${IMAGES}; do
  tmp="www${image#input}"
  basepath=${tmp%.*}
  extension=${image#*.}

  if [[ ! -f "${basepath}.${extension}" ]]; then
    cp -v $image "${basepath}.${extension}"
  fi

  for res in 640 1024 2048; do
    target="${basepath}-${res}w.${extension}"
    if [[ ! -f $target ]]; then
      convert $image -resize $res $target
    fi
  done
done