website-doc.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/sh
  2. #
  3. # vim: expandtab ts=2 :
  4. ARGS=$*
  5. SPHINXBUILD=sphinx-build
  6. TMPDIR='/tmp/offlineimap-sphinx-doctrees'
  7. WEBSITE='./website'
  8. DOCBASE="${WEBSITE}/_doc"
  9. DESTBASE="${DOCBASE}/versions"
  10. VERSIONS_YML="${WEBSITE}/_data/versions.yml"
  11. ANNOUNCES_YML="${WEBSITE}/_data/announces.yml"
  12. ANNOUNCES_YML_LIMIT=31
  13. ANNOUNCES_YML_TMP="${ANNOUNCES_YML}.tmp"
  14. CONTRIB_YML="${WEBSITE}/_data/contribs.yml"
  15. CONTRIB="${DOCBASE}/contrib"
  16. HEADER="# DO NOT EDIT MANUALLY: it is generated by a script (website-doc.sh)."
  17. function fix_pwd () {
  18. cd "$(git rev-parse --show-toplevel)" || \
  19. exit 2 "cannot determine the root of the repository"
  20. test -d "$DESTBASE" || exit 1
  21. }
  22. fix_pwd
  23. version="v$(./offlineimap.py --version)"
  24. #
  25. # Add the doc for the contrib files.
  26. #
  27. function contrib () {
  28. echo $HEADER > "$CONTRIB_YML"
  29. # systemd
  30. cp -afv "./contrib/systemd/README.md" "${CONTRIB}/systemd.md"
  31. echo "- {filename: 'systemd', linkname: 'Integrate with systemd'}" >> "$CONTRIB_YML"
  32. }
  33. #
  34. # Build the sphinx documentation.
  35. #
  36. function api () {
  37. # Build the doc with sphinx.
  38. dest="${DESTBASE}/${version}"
  39. echo "Cleaning target directory: $dest"
  40. rm -rf "$dest"
  41. $SPHINXBUILD -b html -d "$TMPDIR" ./docs/doc-src "$dest"
  42. # Build the JSON definitions for Jekyll.
  43. # This let know the website about the available APIs documentations.
  44. echo "Building Jekyll data: $VERSIONS_YML"
  45. # Erase previous content.
  46. echo > "$VERSIONS_YML" <<EOF
  47. $HEADER
  48. # Used to publish the APIs.
  49. #
  50. # However, it's correct to _remove_ old API docs here. In this case, don't
  51. # forget to adjust the _doc/versions directory too.
  52. EOF
  53. for version in $(ls "$DESTBASE" -1 | sort -nr)
  54. do
  55. echo "- $version"
  56. done | sort -V >> "$VERSIONS_YML"
  57. }
  58. #
  59. # Return title from release entry.
  60. # $1: full release title
  61. #
  62. function parse_releases_get_link () {
  63. echo $1 | sed -r -e 's,^### (OfflineIMAP.*)\),\1,' \
  64. | tr '[:upper:]' '[:lower:]' \
  65. | sed -r -e 's,[\.("],,g' \
  66. | sed -r -e 's, ,-,g'
  67. }
  68. #
  69. # Return version from release entry.
  70. # $1: full release title
  71. #
  72. function parse_releases_get_version () {
  73. echo $1 | sed -r -e 's,^### [a-Z]+ (v[^ ]+).*,\1,'
  74. }
  75. #
  76. # Return date from release entry.
  77. # $1: full release title
  78. #
  79. function parse_releases_get_date () {
  80. echo $1 | sed -r -e 's,.*\(([0-9]+-[0-9]+-[0-9]+).*,\1,'
  81. }
  82. #
  83. # Make Changelog public and save links to them as JSON.
  84. #
  85. function releases () {
  86. # Copy the Changelogs.
  87. for foo in ./Changelog.md ./Changelog.maint.md
  88. do
  89. cp -afv "$foo" "$DOCBASE"
  90. done
  91. # Build the announces JSON list. Format is JSON:
  92. # - {version: '<version>', link: '<link>'}
  93. # - ...
  94. echo "$HEADER" > "$ANNOUNCES_YML"
  95. # Announces for the mainline.
  96. grep -E '^### OfflineIMAP' ./Changelog.md | while read title
  97. do
  98. link="$(parse_releases_get_link "$title")"
  99. v="$(parse_releases_get_version "$title")"
  100. d="$(parse_releases_get_date "$title")"
  101. echo "- {date: '${d}', version: '${v}', link: 'Changelog.html#${link}'}"
  102. done | tee -a "$ANNOUNCES_YML_TMP"
  103. # Announces for the maintenance releases.
  104. grep -E '^### OfflineIMAP' ./Changelog.maint.md | while read title
  105. do
  106. link="$(parse_releases_get_link "$title")"
  107. v="$(parse_releases_get_version "$title")"
  108. d="$(parse_releases_get_date "$title")"
  109. echo "- {date: '${d}', version: '${v}', link: 'Changelog.maint.html#${link}'}"
  110. done | tee -a "$ANNOUNCES_YML_TMP"
  111. sort -nr "$ANNOUNCES_YML_TMP" | head -n $ANNOUNCES_YML_LIMIT >> "$ANNOUNCES_YML"
  112. rm -f "$ANNOUNCES_YML_TMP"
  113. }
  114. function manhtml () {
  115. set -e
  116. cd ./docs
  117. make manhtml
  118. cd ..
  119. cp -afv ./docs/manhtml/* "$DOCBASE"
  120. }
  121. exit_code=0
  122. test "n$ARGS" = 'n' && ARGS='usage' # no option passed
  123. for arg in $ARGS
  124. do
  125. # PWD was fixed at the very beginning.
  126. case "n$arg" in
  127. "nreleases")
  128. releases
  129. ;;
  130. "napi")
  131. api
  132. ;;
  133. "nhtml")
  134. manhtml
  135. ;;
  136. "ncontrib")
  137. contrib
  138. ;;
  139. "nusage")
  140. echo "Usage: website-doc.sh <releases|api|contrib|usage>"
  141. ;;
  142. *)
  143. echo "unkown option $arg"
  144. exit_code=$(( $exit_code + 1 ))
  145. ;;
  146. esac
  147. done
  148. exit $exit_code