#! /bin/sh # # Generate list of Wandystan’s legal acts from the old journal. # Usage: ./genindex.sh > index.html # # Copyright (c) 2017 Paulina Laura Emilia # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extract() { sed -ne " /^<$1>/ { s,^<$1>,, s,$,, p q } " "$2" } pluralise() { first=${1%% *} rest=${1#"$first"} case $first in *[eo]) first=${first%[eo]}a ;; *[ij]a) first=${first%a}e ;; *a) first=${first%a}y ;; *[kg]) first=${first}i ;; *) first=${first}y esac rest=$(printf '%s\n' "$rest" | sed -Ee 's/(ow|jn).[[:>:]]/\1e/g;s/ nr [0-9]+$//g') printf '%s%s\n' "$first" "$rest" } # Create temporary directory for group files: if tmp=$(mktemp -dt genindex.XXXXXX) && [ -d "$tmp" ]; then trap 'rm -rf "$tmp"' 0 else printf '%s: %s\n' "$0" 'Cannot create temporary directory' >&2 exit 1 fi # Extract act names to group files: find . -maxdepth 1 -name 'akt,*.html' | sort -V | while IFS= read -r akt; do title=$(extract h1 "$akt") subtitle=$(extract h2 "$akt") type=${title%% z dnia*} printf '\t\t
  • %s %s
  • \n' \ "${akt#./}" "$title" "$subtitle" >> "$tmp/$type" done # Print header: printf '%s\n\n' ' Archiwum Dziennika Praw Mandragoratu Wandystanu 2004-2007

    Archiwum Dziennika Praw Mandragoratu Wandystanu 2004-2007

    ' # Print index: sec=1 printf '\t

    Spis treści

    \n\t
      \n' for group in "$tmp"/*; do printf '\t\t
    1. %s
    2. \n' \ "$sec" "$(pluralise "${group##*/}")" : $(( sec = sec + 1 )) done | iconv -f ISO8859-2 -t UTF-8 printf '\t
    \n\n' # Print groups: sec=1 for group in "$tmp"/*; do printf '\t

    %s

    \n\t\n\n' : $(( sec = sec + 1 )) done | iconv -f ISO8859-2 -t UTF-8 # Print footer: printf '%s\n' '
    Lista wygenerowana przez genindex.sh
    '