#! /bin/bash # tmpdir="$(mktemp -d)" finish() { rm -rf "$tmpdir" } trap finish EXIT set -euo pipefail # Generate the documentation for the package the calls go:generate package="$(git rev-parse --show-prefix)" # e.g. v1alpha4 version="$(basename "${package}")" version="${version%/}" # e.g. api/core or api/author schema="$(dirname "${package}")" # Move to the repo root cd "$(git rev-parse --show-toplevel)" # Check if the version is released if [[ -d "doc/website/versioned_docs/version-${version}" ]]; then # released version base="doc/website/versioned_docs/version-${version}/${schema}" else # next version base="doc/md/${schema}" fi mkdir -p "$(dirname "${base}")" gomarkdoc --output "${tmpdir}/doc.md" "./${package}" # Fix heading anchors by making them explicit # Refer to https://docusaurus.io/docs/markdown-features/toc#heading-ids sed -E 's/## type ([A-Za-z0-9_]+)/## type \1 {#\1}/' "${tmpdir}/doc.md" > "${tmpdir}/with-header.md" # Remove the annoying package h1 header, docusaurus will use the title front # matter for the page h1 header. grep -v "^# $(basename "${schema}")" "${tmpdir}/with-header.md" > "${tmpdir}/fixed.md" cat "./${package%%/}/header.yaml" "${tmpdir}/fixed.md" > "${base}.md"