File: website-doc.sh

package info (click to toggle)
offlineimap3 0.0~git20211018.e64c254%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,240 kB
  • sloc: python: 8,089; sh: 586; makefile: 81
file content (172 lines) | stat: -rwxr-xr-x 4,096 bytes parent folder | download | duplicates (4)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/sh
#
# vim: expandtab ts=2 :

ARGS=$*

SPHINXBUILD=sphinx-build
TMPDIR='/tmp/offlineimap-sphinx-doctrees'
WEBSITE='./website'
DOCBASE="${WEBSITE}/_doc"
DESTBASE="${DOCBASE}/versions"
VERSIONS_YML="${WEBSITE}/_data/versions.yml"
ANNOUNCES_YML="${WEBSITE}/_data/announces.yml"
ANNOUNCES_YML_LIMIT=31
ANNOUNCES_YML_TMP="${ANNOUNCES_YML}.tmp"
CONTRIB_YML="${WEBSITE}/_data/contribs.yml"
CONTRIB="${DOCBASE}/contrib"
HEADER="# DO NOT EDIT MANUALLY: it is generated by a script (website-doc.sh)."


function fix_pwd () {
  cd "$(git rev-parse --show-toplevel)" || \
    exit 2 "cannot determine the root of the repository"
  test -d "$DESTBASE" || exit 1
}

fix_pwd
version="v$(./offlineimap.py --version)"



#
# Add the doc for the contrib files.
#
function contrib () {
  echo $HEADER > "$CONTRIB_YML"
  # systemd
  cp -afv "./contrib/systemd/README.md" "${CONTRIB}/systemd.md"
  echo "- {filename: 'systemd', linkname: 'Integrate with systemd'}" >> "$CONTRIB_YML"
}



#
# Build the sphinx documentation.
#
function api () {
  # Build the doc with sphinx.
  dest="${DESTBASE}/${version}"
  echo "Cleaning target directory: $dest"
  rm -rf "$dest"
  $SPHINXBUILD -b html -d "$TMPDIR" ./docs/doc-src "$dest"

  # Build the JSON definitions for Jekyll.
  # This let know the website about the available APIs documentations.
  echo "Building Jekyll data: $VERSIONS_YML"
  # Erase previous content.
  echo > "$VERSIONS_YML" <<EOF
$HEADER
# Used to publish the APIs.
#
# However, it's correct to _remove_ old API docs here. In this case, don't
# forget to adjust the _doc/versions directory too.
EOF
  for version in $(ls "$DESTBASE" -1 | sort -nr)
  do
    echo "- $version"
  done | sort -V >> "$VERSIONS_YML"
}



#
# Return title from release entry.
# $1: full release title
#
function parse_releases_get_link () {
  echo $1 | sed -r -e 's,^### (OfflineIMAP.*)\),\1,' \
    | tr '[:upper:]' '[:lower:]' \
    | sed -r -e 's,[\.("],,g' \
    | sed -r -e 's, ,-,g'
}

#
# Return version from release entry.
# $1: full release title
#
function parse_releases_get_version () {
  echo $1 | sed -r -e 's,^### [a-Z]+ (v[^ ]+).*,\1,'
}

#
# Return date from release entry.
# $1: full release title
#
function parse_releases_get_date () {
  echo $1 | sed -r -e 's,.*\(([0-9]+-[0-9]+-[0-9]+).*,\1,'
}

#
# Make Changelog public and save links to them as JSON.
#
function releases () {
  # Copy the Changelogs.
  for foo in ./Changelog.md ./Changelog.maint.md
  do
    cp -afv "$foo" "$DOCBASE"
  done

  # Build the announces JSON list. Format is JSON:
  #       - {version: '<version>', link: '<link>'}
  #       - ...
  echo "$HEADER" > "$ANNOUNCES_YML"
  # Announces for the mainline.
  grep -E '^### OfflineIMAP' ./Changelog.md | while read title
  do
    link="$(parse_releases_get_link "$title")"
    v="$(parse_releases_get_version "$title")"
    d="$(parse_releases_get_date "$title")"
    echo "- {date: '${d}', version: '${v}', link: 'Changelog.html#${link}'}"
  done | tee -a "$ANNOUNCES_YML_TMP"
  # Announces for the maintenance releases.
  grep -E '^### OfflineIMAP' ./Changelog.maint.md | while read title
  do
    link="$(parse_releases_get_link "$title")"
    v="$(parse_releases_get_version "$title")"
    d="$(parse_releases_get_date "$title")"
    echo "- {date: '${d}', version: '${v}', link: 'Changelog.maint.html#${link}'}"
  done | tee -a "$ANNOUNCES_YML_TMP"
  sort -nr "$ANNOUNCES_YML_TMP" | head -n $ANNOUNCES_YML_LIMIT >> "$ANNOUNCES_YML"
  rm -f "$ANNOUNCES_YML_TMP"
}

function manhtml () {
  set -e

  cd ./docs
  make manhtml
  cd ..
  cp -afv ./docs/manhtml/* "$DOCBASE"
}


exit_code=0
test "n$ARGS" = 'n' && ARGS='usage' # no option passed
for arg in $ARGS
do
  # PWD was fixed at the very beginning.
  case "n$arg" in
    "nreleases")
      releases
      ;;
    "napi")
      api
      ;;
    "nhtml")
      manhtml
      ;;
    "ncontrib")
      contrib
      ;;
    "nusage")
      echo "Usage: website-doc.sh <releases|api|contrib|usage>"
      ;;
    *)
      echo "unkown option $arg"
      exit_code=$(( $exit_code + 1 ))
      ;;
  esac
done

exit $exit_code