summaryrefslogtreecommitdiffhomepage
path: root/tests/scripts/webdocs.sh
blob: ce71193bb3342be55a84e1db188b98ba27837a1b (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Integration: the website's pages are generated from README.md and DESIGN.md
# by web/site-page.sh, and they have to come out whole.
#
# The generator used to be an awk program inside the Makefile.  Make reads a
# `$` in a recipe as a variable reference, so it turned the awk `$/` and `$0`
# into nothing, awk exited with a syntax error, the page was written empty and
# nothing said so: the site had no README page and `make webdocs` reported
# success.  These checks are the ones that would have caught that.
repo=https://github.com/skurtz97/zash/blob/main
root=$TESTS/..
mkdir site || exit 1

for d in README:40:README DESIGN:50:Design; do
    name=${d%%:*}; rest=${d#*:}
    weight=${rest%%:*}; title=${rest#*:}
    other=DESIGN
    [ "$name" = DESIGN ] && other=README
    page=site/$name.md
    "$TSH" "$root/web/site-page.sh" "$root/$name.md" "$weight" "$title" \
        "$repo" >"$page" || exit 1

    # Front matter, then a page long enough to be the document.
    if [ "$(sed -n 1p "$page")" = "---" ] &&
        [ "$(sed -n 2p "$page")" = "title: $title" ] &&
        [ "$(sed -n 3p "$page")" = "weight: $weight" ] &&
        [ "$(sed -n 4p "$page")" = "source: $name.md" ] &&
        [ "$(wc -l <"$page")" -gt 100 ]; then
        echo "$name front matter ok"
    else
        echo "$name front matter WRONG"
    fi

    # The site has a logo, its own contents list and the title, so the
    # document's must be gone.  A `#` inside a code block is not a title.
    if grep -q 'align="center"' "$page" || grep -q '^## Contents$' "$page" ||
        sed '/^```/,/^```/d' "$page" | grep -q '^# '; then
        echo "$name header, contents or title still there WRONG"
    else
        echo "$name header, contents and title dropped ok"
    fi

    # No link may still point at a file in the tree.
    if grep -q "](.*\.md" "$page" && ! grep -q "](\.\./" "$page"; then
        echo "$name links WRONG"
    else
        echo "$name links rewritten ok"
    fi

    # The other document is a page of the site, not a file on GitHub.
    if grep -q "]($repo/$other.md" "$page"; then
        echo "$name still links to $other.md on GitHub WRONG"
    else
        echo "$name links to the $other page ok"
    fi
done