Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions extensions/mdbook/test/stitched/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//:defs.bzl", "mdbook")

# This shows how mdBook can include sources from anywhere in the
# repository. However, because mdBook only processes files located
# under the 'src' directory (as configured in book.toml), any files
# from outside the book's package must be rebased into the 'src'
# directory using genrules or other means. The rule's process_wrapper
# ensures that the relative directory structure of these "stitched"
# files is preserved in the temporary build directory.

mdbook(
name = "stitched",
srcs = [
# The main navigation file for the book.
"//test/stitched/src:SUMMARY.md",
# A file rebased from a sibling directory into the book's src/
# directory.
"//test/stitched/src:rebased",
# A file generated within a subpackage and placed in the
# book's src/ directory.
"//test/stitched/src:generated",
],
book = "book.toml",
)

build_test(
name = "stitched_test",
targets = [":stitched"],
)
5 changes: 5 additions & 0 deletions extensions/mdbook/test/stitched/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[book]
authors = ["Stitched Test"]
language = "en"
src = "src"
title = "Stitched Test Book"
1 change: 1 addition & 0 deletions extensions/mdbook/test/stitched/other_srcs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(["chapter_2.md"])
2 changes: 2 additions & 0 deletions extensions/mdbook/test/stitched/other_srcs/chapter_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Chapter 2
Other source.
19 changes: 19 additions & 0 deletions extensions/mdbook/test/stitched/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports_files(["SUMMARY.md"])

# Rebase a file from a different directory into the book's source
# directory. This is necessary because mdBook only processes files
# located under the 'src' directory (as configured in book.toml).
genrule(
name = "rebased",
srcs = ["//test/stitched/other_srcs:chapter_2.md"],
outs = ["chapter_2.md"],
cmd = "cp $< $@",
visibility = ["//test/stitched:__pkg__"],
)

genrule(
name = "generated",
outs = ["chapter_3.md"],
cmd = "echo '# Chapter 3\nGenerated source.' > $@",
visibility = ["//test/stitched:__pkg__"],
)
5 changes: 5 additions & 0 deletions extensions/mdbook/test/stitched/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Summary

- [Chapter 1 (Local source)](chapter_1.md)
- [Chapter 2 (Rebased from sibling directory)](chapter_2.md)
- [Chapter 3 (Generated in subpackage)](chapter_3.md)
2 changes: 2 additions & 0 deletions extensions/mdbook/test/stitched/src/chapter_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Chapter 1
Local source.
Loading