Skip to content

Commit 76da8d3

Browse files
authored
feat: Add support for mdbook (#38)
This should help simplify downloading mdbook and serving the book locally.
1 parent 674d84b commit 76da8d3

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ rm -rf $$TMP_DIR ;\
225225
}
226226
endef
227227

228+
MDBOOK = /tmp/mdbook
229+
.PHONY: build-book
230+
build-book: ## Download mdbook locally if necessary.
231+
docs/build.sh
232+
233+
.PHONY: serve-book
234+
serve-book: build-book ## Build and serve the book with live-reloading enabled
235+
$(MDBOOK) serve docs
228236

229237
## --------------------------------------
230238
## e2e

docs/build.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
os=$(go env GOOS)
22+
arch=$(go env GOARCH)
23+
24+
MDBOOK_VERSION="0.4.15"
25+
26+
# translate arch to rust's conventions (if we can)
27+
if [[ ${arch} == "amd64" ]]; then
28+
arch="x86_64"
29+
elif [[ ${arch} == "x86" ]]; then
30+
arch="i686"
31+
fi
32+
33+
# translate os to rust's conventions (if we can)
34+
ext="tar.gz"
35+
cmd="tar -C /tmp -xzvf"
36+
case ${os} in
37+
windows)
38+
target="pc-windows-msvc"
39+
ext="zip"
40+
cmd="unzip -d /tmp"
41+
;;
42+
darwin)
43+
target="apple-darwin"
44+
;;
45+
linux)
46+
# works for linux, too
47+
target="unknown-${os}-gnu"
48+
;;
49+
*)
50+
target="unknown-${os}"
51+
;;
52+
esac
53+
54+
# grab mdbook
55+
# we hardcode linux/amd64 since rust uses a different naming scheme and it's a pain to tran
56+
echo "downloading mdBook-v${MDBOOK_VERSION}-${arch}-${target}.${ext}"
57+
set -x
58+
curl -sL -o /tmp/mdbook.${ext} "https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdBook-v${MDBOOK_VERSION}-${arch}-${target}.${ext}"
59+
${cmd} /tmp/mdbook.${ext}
60+
chmod +x /tmp/mdbook
61+
62+
# Finally build the book.
63+
(cd docs && /tmp/mdbook build)

0 commit comments

Comments
 (0)