« Back to Index

Shell: Generate Go documentation

View original Gist on GitHub

Tags: #go #shell

Generate golang documentation.bash

#!/bin/bash

set -e

PACKAGE_LIST=""
for pkg in $(go list  ./...); do 
	echo "Generating $pkg ..."
	if [[ "$pkg" == *"internal"* ]]; then
		# Skip internal packages
		:
	else
		PACKAGE_LIST="$PACKAGE_LIST $pkg"
		rm -rf docs/$pkg
		mkdir -p docs/$pkg
		# Piping into tail to skip the go module warning
		godoc -url=pkg/$pkg | tail -n +2 > docs/$pkg/index.html
	fi
done

# Following: https://rohanverma.net/blog/2020/11/24/generating-go-documentation/
echo "Generating gomarkdoc to pandoc ..."
gomarkdoc $PACKAGE_LIST > docs/fastly-tinygo-docs.md
pandoc docs/fastly-tinygo-docs.md \
	--toc \
	--metadata title="Fastly C@E TinyGo - User Docs" \
	-c https://unpkg.com/sakura.css/css/sakura.css \
	--self-contained \
	-o docs/fastly-tinygo-docs.html