2023-05-18 22:50:20 +08:00
# The source of this file is https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/docs.mk.
2023-07-18 16:52:11 +08:00
# A changelog is included in the head of the `make-docs` script.
2023-04-18 18:46:10 +08:00
i n c l u d e v a r i a b l e s . m k
- i n c l u d e v a r i a b l e s . m k . l o c a l
.ONESHELL :
.DELETE_ON_ERROR :
export SHELL := bash
export SHELLOPTS := pipefail:errexit
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rule
.DEFAULT_GOAL : help
# Adapted from https://www.thapaliya.com/en/writings/well-documented-makefiles/
.PHONY : help
help : ## Display this help.
help :
2023-04-24 23:23:33 +08:00
@awk ' BEGIN { \
FS = ": ##" ; \
printf "Usage:\n make <target>\n\nTargets:\n" \
} \
/^[ a-zA-Z0-9_\. \- \/ %] +: ##/ { printf " %-15s %s\n", $$1, $$2 }' \
$( MAKEFILE_LIST)
2023-04-18 18:46:10 +08:00
GIT_ROOT := $( shell git rev-parse --show-toplevel)
PODMAN := $( shell if command -v podman >/dev/null 2>& 1; then echo podman; else echo docker; fi )
i f e q ( $( PROJECTS ) , )
$( error "PROJECTS variable must be defined in variables .mk ")
e n d i f
# Host port to publish container port to.
2023-04-24 23:23:33 +08:00
i f e q ( $( origin DOCS_HOST_PORT ) , u n d e f i n e d )
2023-04-18 18:46:10 +08:00
export DOCS_HOST_PORT := 3002
2023-04-24 23:23:33 +08:00
e n d i f
2023-04-18 18:46:10 +08:00
# Container image used to perform Hugo build.
2023-04-24 23:23:33 +08:00
i f e q ( $( origin DOCS_IMAGE ) , u n d e f i n e d )
2023-04-18 18:46:10 +08:00
export DOCS_IMAGE := grafana/docs-base:latest
2023-04-24 23:23:33 +08:00
e n d i f
2023-04-18 18:46:10 +08:00
2025-04-14 17:47:10 +08:00
# Container image used for Vale linting.
2023-05-18 22:50:20 +08:00
i f e q ( $( origin VALE_IMAGE ) , u n d e f i n e d )
export VALE_IMAGE := grafana/vale:latest
e n d i f
2023-04-18 18:46:10 +08:00
# PATH-like list of directories within which to find projects.
# If all projects are checked out into the same directory, ~/repos/ for example, then the default should work.
2023-04-24 23:23:33 +08:00
i f e q ( $( origin REPOS_PATH ) , u n d e f i n e d )
2023-04-18 18:46:10 +08:00
export REPOS_PATH := $( realpath $( GIT_ROOT) /..)
2023-04-24 23:23:33 +08:00
e n d i f
2023-04-18 18:46:10 +08:00
# How to treat Hugo relref errors.
2023-04-24 23:23:33 +08:00
i f e q ( $( origin HUGO_REFLINKSERRORLEVEL ) , u n d e f i n e d )
2023-04-18 18:46:10 +08:00
export HUGO_REFLINKSERRORLEVEL := WARNING
2023-04-24 23:23:33 +08:00
e n d i f
2023-04-18 18:46:10 +08:00
2024-05-16 19:00:32 +08:00
# Whether to pull the latest container image before running the container.
i f e q ( $( origin PULL ) , u n d e f i n e d )
export PULL := true
e n d i f
2023-04-18 18:46:10 +08:00
.PHONY : docs -rm
docs-rm : ## Remove the docs container.
$( PODMAN) rm -f $( DOCS_CONTAINER)
.PHONY : docs -pull
docs-pull : ## Pull documentation base image.
2023-08-21 15:56:54 +08:00
$( PODMAN) pull -q $( DOCS_IMAGE)
2023-04-18 18:46:10 +08:00
make-docs : ## Fetch the latest make-docs script.
make-docs :
2023-09-21 00:19:40 +08:00
if [ [ ! -f " $( CURDIR) /make-docs " ] ] ; then
2023-04-24 23:23:33 +08:00
echo 'WARN: No make-docs script found in the working directory. Run `make update` to download it.' >& 2
exit 1
fi
2023-04-18 18:46:10 +08:00
.PHONY : docs
2024-05-16 19:00:32 +08:00
docs : ## Serve documentation locally, which includes pulling the latest `DOCS_IMAGE` (default: `grafana/docs-base:latest`) container image. To not pull the image, set `PULL=false`.
i f e q ( $( PULL ) , t r u e )
2023-04-18 18:46:10 +08:00
docs : docs -pull make -docs
2024-05-16 19:00:32 +08:00
e l s e
docs : make -docs
e n d i f
2023-09-21 00:19:40 +08:00
$( CURDIR) /make-docs $( PROJECTS)
2023-04-18 18:46:10 +08:00
2023-04-24 23:23:33 +08:00
.PHONY : docs -debug
docs-debug : ## Run Hugo web server with debugging enabled. TODO: support all SERVER_FLAGS defined in website Makefile.
docs-debug : make -docs
2023-09-21 00:19:40 +08:00
WEBSITE_EXEC = 'hugo server --bind 0.0.0.0 --port 3002 --debug' $( CURDIR) /make-docs $( PROJECTS)
2023-04-24 23:23:33 +08:00
2023-05-18 22:50:20 +08:00
.PHONY : vale
2024-05-16 19:00:32 +08:00
vale : ## Run vale on the entire docs folder which includes pulling the latest `VALE_IMAGE` (default: `grafana/vale:latest`) container image. To not pull the image, set `PULL=false`.
2023-05-18 22:50:20 +08:00
vale : make -docs
2024-05-16 19:00:32 +08:00
i f e q ( $( PULL ) , t r u e )
$( PODMAN) pull -q $( VALE_IMAGE)
e n d i f
2023-09-21 00:19:40 +08:00
DOCS_IMAGE = $( VALE_IMAGE) $( CURDIR) /make-docs $( PROJECTS)
2023-05-18 22:50:20 +08:00
2023-04-24 23:23:33 +08:00
.PHONY : update
update : ## Fetch the latest version of this Makefile and the `make-docs` script from Writers' Toolkit.
2023-04-18 18:46:10 +08:00
curl -s -LO https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/docs.mk
2023-04-24 23:23:33 +08:00
curl -s -LO https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/make-docs
chmod +x make-docs
2025-02-14 18:26:29 +08:00
2025-02-19 17:54:01 +08:00
# ls static/templates/ | sed 's/-template\.md//' | xargs
TOPIC_TYPES := concept multiple-tasks reference section task tutorial visualization
.PHONY : $( patsubst %,topic /%,$ ( TOPIC_TYPES ) )
2025-02-14 18:26:29 +08:00
topic/% : ## Create a topic from the Writers' Toolkit template. Specify the topic type as the target, for example, `make topic/task TOPIC_PATH=sources/my-new-topic.md`.
2025-03-07 18:38:11 +08:00
$(patsubst %,topic/%,$(TOPIC_TYPES)) :
2025-02-14 18:26:29 +08:00
$( if $( TOPIC_PATH) ,,$( error " You must set the TOPIC_PATH variable to the path where the $( @F) topic will be created. For example: make $( @) TOPIC_PATH=sources/my-new-topic.md " ) )
mkdir -p $( dir $( TOPIC_PATH) )
curl -s -o $( TOPIC_PATH) https://raw.githubusercontent.com/grafana/writers-toolkit/refs/heads/main/docs/static/templates/$( @F) -template.md