Skip to content

Commit 6615f48

Browse files
authored
[docs] Add PDF/DOCX export pipeline (#232)
* [docs] Add PDF/DOCX export pipeline - Introduce multi-stage werf build for print artefacts using a dedicated base image with WeasyPrint, Pandoc, and Node tooling; the print-artifacts stage renders HTML via a local server, runs the export script per locale, and feeds results into the web image so downloads are served at deploy time - Add a make target that builds the print-artifacts image and extracts the generated files locally; refactor the help system to use self-documenting inline comments with awk-based parsing and add ARM platform detection for cross-compilation - Enable the print output format and downloads shortcode in both EN/RU documentation landing pages; configure per-language PDF titles and the global pdf toggle in the site parameters - Bump hugo-web-product-module from v0.1.17 to v0.1.20 * [docs] Add PDF/DOCX export pipeline - Introduce multi-stage werf build for print artefacts using a dedicated base image with WeasyPrint, Pandoc, and Node tooling; the print-artifacts stage renders HTML via a local server, runs the export script per locale, and feeds results into the web image so downloads are served at deploy time - Add a make target that builds the print-artifacts image and extracts the generated files locally; refactor the help system to use self-documenting inline comments with awk-based parsing and add ARM platform detection for cross-compilation - Enable the print output format and downloads shortcode in both EN/RU documentation landing pages; configure per-language PDF titles and the global pdf toggle in the site parameters - Bump hugo-web-product-module from v0.1.17 to v0.1.21
1 parent 8cb8dc3 commit 6615f48

8 files changed

Lines changed: 154 additions & 44 deletions

File tree

Makefile

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,91 @@
11
# Makefile for the Hugo website
22

3+
PLATFORM_NAME := $(shell uname -p)
4+
ifneq ($(filter arm%,$(PLATFORM_NAME)),)
5+
export WERF_PLATFORM=linux/amd64
6+
endif
7+
8+
.DEFAULT_GOAL := help
9+
310
# Tools / variables (can be overridden on the command line)
411
HUGO ?= hugo
512
BIND ?= 0.0.0.0
613
SERVE_FLAGS ?= --cleanDestinationDir --bind=$(BIND)
714
HUGOFLAGS ?= --minify
815
MARKDOWNLINT_VERSION ?= v0.45.0
16+
WERF ?= werf
917
WERF_PLATFORM ?= linux/amd64
1018

1119
CURRENT_UID ?= $(shell id -u)
1220
CURRENT_GID ?= $(shell id -g)
1321
PORTS_TO_FREE ?= 80 1313 1314
1422

15-
.PHONY: help serve build down lint-markdown lint-markdown-fix mod
16-
.PHONY: help serve build down lint-markdown lint-markdown-fix mod free-ports
17-
18-
help:
19-
@echo "Usage: make [target]"
20-
@echo
21-
@echo "Common targets:"
22-
@echo " up Start documentation (available at http://localhost and http://ru.localhost)"
23-
@echo " serve Start Hugo dev server (hugo serve --cleanDestinationDir)"
24-
@echo " build Build the site to ./public"
25-
@echo " down Stop and remove documentation containers"
26-
@echo " lint-markdown Lint markdown files"
27-
@echo " lint-markdown-fix Fix markdown files automatically"
28-
@echo " mod Clean up Hugo modules (hugo mod tidy)"
29-
@echo " help Show this help"
30-
@echo
31-
@echo "Variables (can be overridden):"
32-
@echo " HUGO=$(HUGO)"
33-
@echo " PORT=$(PORT)"
34-
@echo " BIND=$(BIND)"
35-
@echo " BASEURL=$(BASEURL)"
36-
@echo " MARKDOWNLINT_VERSION=$(MARKDOWNLINT_VERSION)"
37-
38-
up:
23+
PRODUCT_CODE ?= $(shell awk '/^ productCode:/ {print tolower($$2); exit}' config/_default/hugo.yaml)
24+
25+
##@ Main
26+
27+
up: ## Start documentation (available at http://localhost and http://ru.localhost)
3928
@$(MAKE) down
4029
@$(MAKE) free-ports
4130
@UID=$(CURRENT_UID) GID=$(CURRENT_GID) docker compose up
4231

43-
free-ports:
44-
@containers="$$(for port in $(PORTS_TO_FREE); do docker ps -q --filter "publish=$$port"; done | sort -u)"; \
45-
if [ -n "$$containers" ]; then \
46-
echo "Stopping containers using ports $(PORTS_TO_FREE): $$containers"; \
47-
docker stop $$containers; \
48-
fi
49-
50-
down:
51-
docker compose rm -f
52-
docker compose down --remove-orphans
53-
54-
serve:
32+
serve: ## Start Hugo dev server (hugo serve --cleanDestinationDir)
5533
$(HUGO) serve $(SERVE_FLAGS)
5634

57-
build:
35+
build: ## Build the site to ./public
5836
@echo "Building site to ./public..."
5937
$(HUGO) $(HUGOFLAGS)
6038

61-
lint-markdown:
39+
pdf: ## Build the site and generate PDF+DOCX exports via werf
40+
##~ Output: public/{en,ru}/documentation/downloads/print/<productCode>.{pdf,docx}
41+
##~ Need external registry (e.g. export WERF_REPO=localhost:4999/docs) to run.
42+
@echo "Building print-artifacts via werf..."
43+
@$(WERF) build print-artifacts
44+
@echo "Extracting PDF/DOCX ($(PRODUCT_CODE)) to ./public/{en,ru}/documentation/downloads/print/..."
45+
@IMG=$$($(WERF) stage image print-artifacts) && \
46+
CID=$$(docker create $$IMG) && \
47+
trap "docker rm $$CID >/dev/null" EXIT && \
48+
mkdir -p ./public/en/documentation/downloads/print ./public/ru/documentation/downloads/print && \
49+
docker cp $$CID:/out/en/documentation/downloads/print/. ./public/en/documentation/downloads/print/ && \
50+
docker cp $$CID:/out/ru/documentation/downloads/print/. ./public/ru/documentation/downloads/print/
51+
@echo "Done. Files: public/{en,ru}/documentation/downloads/print/$(PRODUCT_CODE).{pdf,docx}"
52+
53+
down: ## Stop and remove documentation containers
54+
docker compose rm -f
55+
docker compose down --remove-orphans
56+
57+
##@ Linters
58+
59+
lint-markdown: ## Lint markdown files
6260
@echo "Linting markdown files..."
6361
@docker run --rm -v "$(PWD):/workdir" -w /workdir ghcr.io/igorshubovych/markdownlint-cli:$(MARKDOWNLINT_VERSION) "**/*.md" -c markdownlint.yaml
6462

65-
lint-markdown-fix:
63+
lint-markdown-fix: ## Lint and auto-fix markdown files
6664
@echo "Fixing markdown files..."
6765
@docker run --rm -v "$(PWD):/workdir" -w /workdir ghcr.io/igorshubovych/markdownlint-cli:$(MARKDOWNLINT_VERSION) "**/*.md" -c markdownlint.yaml --fix
6866

69-
mod:
67+
##@ Helpers
68+
69+
mod: ## Clean up Hugo modules (hugo mod tidy)
7070
@echo "Cleaning up Hugo modules..."
7171
$(HUGO) mod tidy
7272

73+
free-ports: ## Stop containers using known dev ports ($(PORTS_TO_FREE))
74+
@containers="$$(for port in $(PORTS_TO_FREE); do docker ps -q --filter "publish=$$port"; done | sort -u)"; \
75+
if [ -n "$$containers" ]; then \
76+
echo "Stopping containers using ports $(PORTS_TO_FREE): $$containers"; \
77+
docker stop $$containers; \
78+
fi
79+
80+
help: ## Show this help message
81+
@echo 'Usage: make [target]'
82+
@echo ''
83+
@echo 'Available targets:'
84+
@awk 'BEGIN {\
85+
FS = ":.*?## "; \
86+
} \
87+
/^##@/ { printf "\n%s\n", substr($$0, 5) } \
88+
/^[a-zA-Z0-9_-]+:.*?## / { printf " %-20s %s\n", $$1, $$2 } \
89+
/^.?.?##~/ { printf " %-20s %s\n", "", substr($$1, 6) }' $(MAKEFILE_LIST)
90+
91+
.PHONY: help up serve build pdf down lint-markdown lint-markdown-fix mod free-ports

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ To run locally:
1717
```
1818

1919
1. Open `http://localhost/products/development-platform/documentation/` in your browser (for the english version) or `http://ru.localhost/products/development-platform/documentation/` (for the russian version).
20+
21+
## Generating PDF/DOCX exports
22+
23+
Run `make pdf` — the werf `print-artifacts` image is built and the resulting files are
24+
extracted into `public/{en,ru}/documentation/downloads/print/development-platform.{pdf,docx}`.
25+
On deploy the same image is imported into `web`, so the site serves them under the same URL.
26+
27+
This project enables PDF/DOCX through:
28+
29+
- `params.pdf: true` in `config/_default/hugo.yaml`;
30+
- `outputs: [HTML, search, print]` in the front matter of `content/documentation/_index.{md,ru.md}`;
31+
- sidebar download links (rendered automatically by the module theme).
32+
33+
For the full description of the pipeline (werf stages, requirements, how to enable/disable
34+
for a new product website) see the [PDF/DOCX exports section in the module README](https://github.com/deckhouse/hugo-web-product-module/blob/main/README.md#pdfdocx-exports).

config/_default/hugo.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ params:
6969
# Enable Lunr.js offline search
7070
offlineSearch: true
7171

72+
# Enable PDF/DOCX documentation exports (generated in CI, downloadable from sidebar).
73+
pdf: true
74+
7275
# Global relevant links.
7376
links:
7477

@@ -104,10 +107,12 @@ languages:
104107
baseURL: https://deckhouse.io/products/development-platform/
105108
params:
106109
description: ""
110+
pdfTitle: "Deckhouse Development Platform Documentation"
107111
ru:
108112
disabled: false
109113
weight: 1
110114
title: Deckhouse Development Platform
111115
baseURL: https://deckhouse.ru/products/development-platform/
112116
params:
113117
description: ""
118+
pdfTitle: "Документация Deckhouse Development Platform"

content/documentation/_index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ params:
77
outputs:
88
- HTML
99
- search
10+
- print
1011
cascade:
1112
params:
1213
simple_list: true
1314
---
1415

16+
{{< downloads >}}
17+
1518
Deckhouse Development Platform (DDP) is a comprehensive solution for managing all stages of development through a single interface.
1619

1720
The platform helps IT professionals work more efficiently — it automates operations related to the service lifecycle and provides tools to assess the overall system performance.

content/documentation/_index.ru.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ params:
77
outputs:
88
- HTML
99
- search
10+
- print
1011
cascade:
1112
params:
1213
simple_list: true
1314
---
1415

16+
{{< downloads >}}
17+
1518
Deckhouse Development Platform (DDP) — это комплексное решение для управления всеми этапами разработки через единое окно. Платформа автоматизирует операции, связанные с жизненным циклом сервисов, и предоставляет инструменты для оценки работы всей системы.
1619

1720
## Основные возможности

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ module github.com/deckhouse/website-development-platform
44

55
go 1.24.2
66

7-
require github.com/deckhouse/hugo-web-product-module v0.1.17 // indirect
7+
require github.com/deckhouse/hugo-web-product-module v0.1.21 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/deckhouse/hugo-web-product-module v0.1.17 h1:HZ9xxXlUYo7geiTyaZTXk0JFvT0xOkXfYaOeXdUmzVE=
2-
github.com/deckhouse/hugo-web-product-module v0.1.17/go.mod h1:iLVlLSCkbOoi7RjYm5RjwAQi+Whs6DjSumhaH1GBjqw=
1+
github.com/deckhouse/hugo-web-product-module v0.1.21 h1:Dxjcd45jRa1EKaCMUnhWjauZnkGlRVa3l/8S9YeSUew=
2+
github.com/deckhouse/hugo-web-product-module v0.1.21/go.mod h1:iLVlLSCkbOoi7RjYm5RjwAQi+Whs6DjSumhaH1GBjqw=

werf.yaml

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,75 @@ git:
1818
stageDependencies:
1919
setup: ['**/*']
2020
---
21+
image: print-base
22+
from: ubuntu:24.04
23+
final: true
24+
shell:
25+
beforeInstall:
26+
- export DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes
27+
- apt-get update -qq
28+
- apt-get install -y -qq --no-install-recommends apt-utils
29+
- apt-get install -y -qq --no-install-recommends weasyprint pandoc poppler-utils fonts-dejavu-core fonts-liberation ca-certificates curl gnupg git
30+
- curl -fsSL https://deb.nodesource.com/setup_24.x 2>/dev/null | bash - >/dev/null 2>&1
31+
- apt-get install -y -qq --no-install-recommends nodejs
32+
- mkdir -p /deps && cd /deps && npm init -y >/dev/null
33+
- cd /deps && npm install --silent --no-audit --no-fund cheerio http-server jszip
34+
- apt-get autoclean && apt-get clean
35+
---
36+
image: print-artifacts
37+
fromImage: print-base
38+
final: false
39+
import:
40+
- image: web-artifacts
41+
add: /out
42+
to: /site
43+
before: setup
44+
stage: setup
45+
git:
46+
- add: /
47+
to: /src
48+
includePaths:
49+
- go.mod
50+
- config/
51+
stageDependencies:
52+
setup: ['**/*']
53+
shell:
54+
setup:
55+
- |
56+
set -e
57+
PDF_ENABLED=$(awk '/^ pdf:/ {print tolower($2); exit}' /src/config/_default/hugo.yaml)
58+
mkdir -p /out
59+
if [ "$PDF_ENABLED" != "true" ]; then
60+
echo "params.pdf is not true — skipping PDF/DOCX generation."
61+
cp -a /site/. /out/
62+
exit 0
63+
fi
64+
git config --global advice.detachedHead false
65+
export NODE_PATH=/deps/node_modules
66+
export PUBLIC_DIR=/site
67+
HUGO_TEMPLATE_VER=$(awk -v m='github.com/deckhouse/hugo-web-product-module' \
68+
'{for(i=1;i<=NF;i++) if($i==m && $(i+1) ~ /^v/) {print $(i+1); exit}}' /src/go.mod)
69+
export PRODUCT_CODE=$(awk '/^ productCode:/ {print tolower($2); exit}' /src/config/_default/hugo.yaml)
70+
test -n "$HUGO_TEMPLATE_VER" || { echo "ERROR: cannot parse hugo-web-product-module version from go.mod"; exit 1; }
71+
test -n "$PRODUCT_CODE" || { echo "ERROR: cannot parse params.productCode from config/_default/hugo.yaml"; exit 1; }
72+
git clone --depth=1 --filter=blob:none --sparse \
73+
--branch "$HUGO_TEMPLATE_VER" \
74+
https://github.com/deckhouse/hugo-web-product-module.git /tmp/tpl
75+
git -C /tmp/tpl sparse-checkout set .github/scripts
76+
mv /tmp/tpl/.github/scripts /scripts
77+
rm -rf /tmp/tpl
78+
(cd /site && /deps/node_modules/.bin/http-server -p 8088 -s >/tmp/http.log 2>&1 &)
79+
for i in $(seq 1 30); do curl -sf http://localhost:8088/ >/dev/null && break; sleep 1; done
80+
node /scripts/print-export.js en http://localhost:8088
81+
node /scripts/print-export.js ru http://localhost:8088
82+
cp -a /site/. /out/
83+
---
2184
image: web
2285
fromImage: nginx:1.29.3-alpine
86+
final: true
2387
import:
24-
- image: web-artifacts
88+
- image: print-artifacts
2589
add: /out
2690
to: /app
2791
before: setup
92+
stage: setup

0 commit comments

Comments
 (0)