Skip to content

Commit

Permalink
feat: moves the example repo in
Browse files Browse the repository at this point in the history
the ebook-example repo is now in this repo too
  • Loading branch information
filmil committed Dec 22, 2024
1 parent 9b18039 commit 2e0e6b9
Show file tree
Hide file tree
Showing 20 changed files with 420 additions and 6 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ebook-example
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -22,3 +22,5 @@ jobs:
uses: actions/checkout@v2
- name: Build
run: "bazel build //..."
- name: Test
run: "cd ebook-example && bazel build //..."
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ LaTeX supported is somewhat limited).

# Quick start

If you are impatient to see the rules in action, check out an example book in a
separate [ebook example github repository][example].
If you are impatient to see the rules in action, check out an example book in [the example repository][example].

[example]: https://www.github.com/filmil/ebook-example
[example]: ebook-example/README.md

# Defined build rules

Expand Down
3 changes: 1 addition & 2 deletions build/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def bazel_ebook_repositories():
git_repository(
name = "gotopt2",
remote = "https://github.com/filmil/gotopt2",
commit = "97d6b1b0663a976eba231cac93aefbfdca52f9d6",
shallow_since = "1593765180 -0700",
commit = "50751ce0722cc2ccc4066ccb287675d8875d685e",
)

1 change: 1 addition & 0 deletions ebook-example/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.0.0
10 changes: 10 additions & 0 deletions ebook-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.sconsign.dblite
*.pdf
*.mobi
*.epub
*.log
*.html
*.xhtml
*.opf
outdir
bazel-*
48 changes: 48 additions & 0 deletions ebook-example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load("@bazel_ebook//build:rules.bzl",
"asymptote",
"ebook_epub",
"ebook_kindle",
"ebook_pdf",
"markdown_lib",
)

asymptote(
name = "test",
srcs = ["test.asy"],
deps = ["//images:test2"],
)

markdown_lib(
name = "md",
srcs = [
"book.ch001.md",
"book.ch002.md",
"book.ch004.md",
],
deps = [
"//images:dot",
"//images:md",
":test",
],
)

ebook_epub(
name = "book_epub",
deps = [":md"],
metadata_xml = "epub-metadata.xml",
title_yaml = "title.yaml",
)

ebook_pdf(
name = "book_pdf",
deps = [":md"],
metadata_xml = "epub-metadata.xml",
title_yaml = "title.yaml",
)

ebook_kindle(
name = "book_kindle",
deps = [":md"],
metadata_xml = "epub-metadata.xml",
title_yaml = "title.yaml",
)
79 changes: 79 additions & 0 deletions ebook-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Introduction

Here is a minimal example of using Markdown to write a sciency book that
includes source code listings or equations. "Sciency" because it's assumed
that the amount of listings or equations is small, and their relationship
uncomplicated.

The book content is generated in several formats:

* PDF (e.g. for printing on paper)
* ePub (for electronic readers that support it, basically anything *except*
Kindle)
* mobi (for Kindle)

# Prerequisites

* [bazel](https://bazel.io), for building.
* [docker](https://docker.io), because part of the bazel build process needs
docker


# Building

```
bazel build //:all
```

Yes, it's that easy. This will run the commands needed to produce a PDF file,
an ePub file and a mobi (Kindle) format file. Find those files in the
`bazel-bin` directory once the build process ends.

If you want to build specific formats, the following commands apply:

```
bazel build //:book_epub
```

This will build a book in the EPUB format. Once build completes, find it in
the directory `bazel-bin/book_epub.epub`.

```
bazel build //:book_kindle
```

This will build a book in Kindle's MOBI format. Once the build completes, find
it in the directory `bazel-bin/book_kindle.mobi`. You should be able to upload
this book to either your Amazon digital library, or your Kindle device and read
it right away.

# Cleanup

```
bazel clean
```

Yes, it's that easy.

# Caveats

* The equations for the mobi format are generated as 300dpi files. Epub is
currently unusable because of this; if epub is needed, then we need a
completely separate epub build rule that builds it directly.
* The build script generates html with embedded images for equations. Probably
we need something similar to epub production above.
* The `epub-metadata.xml` file actually *must not* be well-formed XML. Only
bare "Dublin core" markup elements are allowed if you want that markup XML to
make it into the actual book contents. I don't quite understand why, but
that is how things are today.
* Apparently the `epub-metadata.xml` gets ignored if you build your ebook from
markdown. This matters for the directly-generated epub version which is made
directly from the Markdown source (in contrast to the `.mobi` version which
requires several steps to produce)

# TODO

* Add an example title page.
* Add an example generated figure e.g. with tikZ or some other involved
drawing program.

56 changes: 56 additions & 0 deletions ebook-example/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# Go build rules
http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains(version = "1.18.3")
http_archive(
name = "bazel_gazelle",
sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz",
],
)
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
gazelle_dependencies()

local_repository(
name = "bazel_ebook",
path = "..",
)
#git_repository(
#name = "bazel_ebook",
#remote = "https://github.com/filmil/bazel-ebook",
#commit = "09181e87bb1e2ffb2988180438f0f6bb464061c5",
#shallow_since = "1634887024 -0700",
#)

git_repository(
name = "bazel_rules_bid",
remote = "https://github.com/filmil/bazel-rules-bid.git",
commit = "04b599ec790fe4572dfb851e145c791cb5022c15",
shallow_since = "1676537869 -0800"
)
load("@bazel_rules_bid//build:repositories.bzl", "bazel_bid_repositories")
bazel_bid_repositories()

load("@gotopt2//build:deps.bzl", "gotopt2_dependencies")
gotopt2_dependencies()

load(
"@bazel_ebook//build:repositories.bzl",
"bazel_ebook_repositories",
)

bazel_ebook_repositories()

91 changes: 91 additions & 0 deletions ebook-example/book.ch001.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Hello world!

I'm a test Markdown document.

**Here's some bold text** and *here's some italic text*. `This is inline code`.

# Markdown Tables

First Name | Last Name | Location | Allegiance
------------|-------------|---------------------|-----------------
Mance | Rayder | North of the Wall | Wildlings
Margaery | Tyrell | The Reach | House Tyrell
Danerys | Targaryen | Meereen | House Targaryen
Tyrion | Lannister | King's Landing | House Lannister

# Code blocks

This code
is in
a code block.

Here's a syntax-highlighted code block:

```python
#!/usr/bin/env python3

import sys

if __name__ == '__main__':
print('This is highlighted Python code!')
sys.exit(0)
```

# Page Layout with \LaTeX\ Commands

Here's a forced page break.

\pagebreak

# LaTeX support

This document supports inline \LaTeX!

Here's the proof: $\frac{n!}{k!(n-k)!} = \binom{n}{k}$

Creating a footnote is easy.\footnote{An example footnote.}

Here's an equation:

$$
x = a_0 + \cfrac{1}{a_1
+ \cfrac{1}{a_2
+ \cfrac{1}{a_3 + \cfrac{1}{a_4} } } }
$$

Here are some numbered equations:

$$
f(x)=(x+a)(x+b)
$$

$$
5^2 - 5 = 20
$$

$$
a = bq + r
$$

Here's some multi-line math stuff:

$$
u(x) =
\begin{cases}
\exp{x} & \text{if } x \geq 0 \\
1 & \text{if } x < 0
\end{cases}
$$

\begin{align*}
f(x) &= (x+a)(x+b) \\
&= x^2 + (a+b)x + ab
\end{align*}

# Images

Let's try some images.

![Here is an image of a Pythagorean tree.](test.asy.png)


5 changes: 5 additions & 0 deletions ebook-example/book.ch002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Chapter two

Some text here.

![Here is an image of a Pythagorean tree again.](images/test1.asy.png)
5 changes: 5 additions & 0 deletions ebook-example/book.ch004.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Chapter four

Some text here.

![Here is a simple graph](images/simple_graph.dot.png)
3 changes: 3 additions & 0 deletions ebook-example/epub-metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<dc:title id="epub-title-1">Ebook Example</dc:title>
<dc:title id="epub-title-2">How to write an ebook in markdown.</dc:title>
<dc:creator>Filip Filmar</dc:creator>
31 changes: 31 additions & 0 deletions ebook-example/images/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@bazel_ebook//build:rules.bzl",
"asymptote",
"dot_png",
"markdown_lib",
)

package(
default_visibility = ["//visibility:public"],
)

asymptote(
name = "test2",
srcs = ["test1.asy"],
)

asymptote(
name = "test3",
srcs = ["test2.asy"],
)


markdown_lib(
name = "md",
srcs = ["book.ch003.md",],
deps = [":test3"],
)

dot_png(
name = "dot",
srcs = ["simple_graph.dot"],
)
5 changes: 5 additions & 0 deletions ebook-example/images/book.ch003.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Chapter three

Some text here.

![Local pythagorean tree](images/test2.asy.png)
8 changes: 8 additions & 0 deletions ebook-example/images/simple_graph.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
graph {
a -- b;
b -- c;
a -- c;
d -- c;
e -- c;
e -- a;
}
Loading

0 comments on commit 2e0e6b9

Please sign in to comment.