forked from martinthomson/i-d-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-readme.sh
executable file
·93 lines (76 loc) · 2.55 KB
/
setup-readme.sh
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
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
# Usage: $0 <user> <repo> [draftxml ...]
user="$1"
repo="$2"
default_branch="${DEFAULT_BRANCH:-$($(dirname "$0")/default-branch.py)}"
shift 2
githubio="https://${user}.github.io/${repo}/#go"
function fixup_other_md() {
markdown=(LICENSE.md CONTRIBUTING.md)
s='s~{WG_NAME}~'"$1"'~g'
s="$s"';s~{GITHUB_USER}~'"$user"'~g'
s="$s"';s~{GITHUB_REPO}~'"$repo"'~g'
s="$s"';s~{GITHUB_BRANCH}~'"$default_branch"'~g'
sed -i~ -e "$s" "${markdown[@]}"
for i in "${markdown[@]}"; do
rm -f "$i"~
done
}
function get_title() {
if hash xmllint >/dev/null 2>&1; then
title=($(xmllint --xpath '/rfc/front/title/text()' "$1"))
else
# sed kludge if xmllint isn't available
title=($(sed -e '/<title[^>]*>/,/<\/title>/{s/.*<title[^>]*>//;/<\/title>/{s/<\/title>.*//;H;x;q;};H;};d' "$1"))
fi
# haxx: rely on bash parameter normalization to remove redundant whitespace
echo "${title[*]}"
}
first=true
for d in "$@"; do
fullname="${d%.xml}"
author=$(echo "${fullname}" | cut -f 2 -d - -)
wg=$(echo "${fullname}" | cut -f 3 -d - -)
wgupper=$(echo "${wg}" | tr 'a-z' 'A-Z')
title=$(get_title "$d")
if "$first"; then
fixup_other_md "$wg"
if [ "$author" = "ietf" ]; then
status="Working Group"
status_full="IETF [${wgupper} Working Group](https://datatracker.ietf.org/wg/${wg}/documents/) Internet-Draft"
else
status="Individual"
status_full="individual Internet-Draft"
fi
if [ $# -gt 1 ]; then
echo "# ${wgupper} Drafts"
status_full="${status_full}s"
else
echo "# $title"
status_full="the ${status_full}, \"${title}\""
fi
echo
echo "This is the working area for ${status_full}."
first=false
fi
if [ $# -gt 1 ]; then
echo
echo "## $title"
fi
echo
echo "* [Editor's Copy](${githubio}.${fullname}.html)"
echo "* [${status} Draft](https://datatracker.ietf.org/doc/html/${fullname})"
echo "* [Compare Editor's Copy to ${status} Draft](${githubio}.${fullname}.diff)"
done
cat <<EOF
## Building the Draft
Formatted text and HTML versions of the draft can be built using \`make\`.
\`\`\`sh
$ make
\`\`\`
This requires that you have the necessary software installed. See
[the instructions](https://github.com/martinthomson/i-d-template/blob/master/doc/SETUP.md).
## Contributing
See the
[guidelines for contributions](https://github.com/${user}/${repo}/blob/${default_branch}/CONTRIBUTING.md).
EOF