summaryrefslogtreecommitdiffstats
path: root/js/src/doc/lib/make-bibliography.sh
blob: 33068ca9c47a85f1f39b7cb4ec90a18f289a30e1 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash

# Generate a Markdown bibliography file --- that is, definitions for
# reference-style link labels --- from a documentation directory's
# config.sh file.
#
# Usage:
#   make-bibliography.sh [--mdn] CONFIG CITING-URL
#
# where:
# - CONFIG is the name of the config.sh file to process; and
# - CITING-URL is the absolute URL at which the document using these labels
#   will appear. The links we output use URLs relative to CITING-URL to
#   refer to the URLs given in CONFIG.
#
# If given the --mdn flag, generate links that are correct for files
# as they appear in format.sh's OUTPUTDIR, not for publishing on MDN.

set -eu

mdn=false

while true; do
    case "${1-}" in
        '--mdn')
            mdn=true
            shift
            ;;
        *)
            break
            ;;
    esac
done

lib=$(dirname $0)
config=$1
citing=$2

source "$lib/common.sh"

source "$lib/dummy-config.sh"

label() {
    local label=$1; shift
    local fragment=
    case "$1" in
        '#'*)
            fragment=$1; shift
            ;;
    esac
    local title=${1:+ \"$1\"}

    citing_prefix=$(dirname "$citing")/
    if $mdn; then
        echo "[$label]: $(relative "$citing_prefix" "$BASE_URL$RELATIVE_URL")$fragment$title"
    else
        echo "[$label]: ${INPUT_FILE/md/html}$fragment$title"
    fi
}

absolute-label() {
    local label=$1
    local absolute_url=$2
    local title=$3

    echo "[$label]: $absolute_url${title:+ \"$title\"}"
}

resource() {
    local label=$1 file=$2 absolute_url=$3

    if [ -n "$label" ]; then
        if $mdn; then
            echo "[$label]: $absolute_url"
        else
            echo "[$label]: $file"
        fi
    fi
}

source "$config"