Skip to content

Commit c30a6eb

Browse files
authored
Refactor repository structure to include translations (#352)
1 parent f5f8078 commit c30a6eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+9184
-299
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
MDBOOK_VERSION=0.4.28
2+
MDBOOK_I8N_HELPERS_VERSION=0.1.0

.github/workflows/build.yml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Test mdbook chapters
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
mdbook-test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Setup Rust cache
20+
uses: ./.github/workflows/setup-rust-cache
21+
22+
- name: Install mdbook
23+
uses: ./.github/workflows/install-mdbook
24+
25+
- name: Test code snippets
26+
run: mdbook test
27+
28+
# TODO: Activate when first translation is available
29+
# i18n-helpers:
30+
# runs-on: ubuntu-latest
31+
# steps:
32+
# - name: Checkout
33+
# uses: actions/checkout@v3
34+
35+
# - name: Install Gettext
36+
# run: sudo apt install gettext
37+
38+
# - name: Setup Rust cache
39+
# uses: ./.github/workflows/setup-rust-cache
40+
41+
# - name: Install mdbook
42+
# uses: ./.github/workflows/install-mdbook
43+
44+
# - name: Generate po/messages.pot
45+
# run: mdbook build -d po
46+
# env:
47+
# MDBOOK_OUTPUT: '{"xgettext": {"pot-file": "messages.pot"}}'
48+
49+
# - name: Test messages.pot
50+
# run: msgfmt --statistics -o /dev/null po/messages.pot
51+
52+
# - name: Expand includes without translation
53+
# run: mdbook build -d expanded
54+
# env:
55+
# MDBOOK_OUTPUT: '{"markdown": {}}'
56+
57+
# - name: Expand includes with no-op translation
58+
# run: mdbook build -d no-op
59+
# env:
60+
# MDBOOK_OUTPUT: '{"markdown": {}}'
61+
# MDBOOK_PREPROCESSOR__GETTEXT__PO_FILE: po/messages.pot
62+
63+
# - name: Compare no translation to no-op translation
64+
# run: diff --color=always --unified --recursive expanded no-op
65+
66+
# find-translations:
67+
# runs-on: ubuntu-latest
68+
# outputs:
69+
# languages: ${{ steps.find-translations.outputs.languages }}
70+
# steps:
71+
# - name: Checkout
72+
# uses: actions/checkout@v3
73+
74+
# - name: Find translations
75+
# id: find-translations
76+
# shell: python
77+
# run: |
78+
# import os, json, pathlib
79+
# languages = [p.stem for p in pathlib.Path("po").iterdir() if p.suffix == ".po"]
80+
# github_output = open(os.environ["GITHUB_OUTPUT"], "a")
81+
# github_output.write("languages=")
82+
# json.dump(sorted(languages), github_output)
83+
84+
# translations:
85+
# runs-on: ubuntu-latest
86+
# needs:
87+
# - find-translations
88+
# strategy:
89+
# matrix:
90+
# language: ${{ fromJSON(needs.find-translations.outputs.languages) }}
91+
# env:
92+
# MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }}
93+
# steps:
94+
# - name: Checkout
95+
# uses: actions/checkout@v3
96+
97+
# - name: Install Gettext
98+
# run: sudo apt install gettext
99+
100+
# - name: Setup Rust cache
101+
# uses: ./.github/workflows/setup-rust-cache
102+
103+
# - name: Install mdbook
104+
# uses: ./.github/workflows/install-mdbook
105+
106+
# - name: Test ${{ matrix.language }} translation
107+
# run: msgfmt --statistics -o /dev/null po/${{ matrix.language }}.po
108+
109+
# - name: Build book with ${{ matrix.language }} translation
110+
# run: mdbook build
111+
112+
# - name: Upload ${{ matrix.language }} translation
113+
# uses: actions/upload-artifact@v3
114+
# with:
115+
# name: rust-design-patterns-${{ matrix.language }}
116+
# path: book/
117+
118+
# - name: Test code snippets with ${{ matrix.language }} translation
119+
# run: mdbook test

.github/workflows/ci.yml

-53
This file was deleted.

.github/workflows/gh-pages.yml

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Install mdbook and dependencies
2+
3+
description: Install the mdbook with the dependencies we need.
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Read mdbook version from .env
9+
id: mdbook-version
10+
run: |
11+
. ./.env
12+
echo "::set-output name=MDBOOK_VERSION::${MDBOOK_VERSION}"
13+
shell: bash
14+
15+
- name: Read mdbook-i8n-helpers version from .env
16+
id: mdbook-i8n-helpers-version
17+
run: |
18+
. ./.env
19+
echo "::set-output name=MDBOOK_I8N_HELPERS_VERSION::${MDBOOK_I8N_HELPERS_VERSION}"
20+
shell: bash
21+
22+
# The --locked flag is important for reproducible builds.
23+
- name: Install mdbook
24+
run: cargo install mdbook --locked --version '${{ steps.mdbook-version.outputs.MDBOOK_VERSION }}'
25+
shell: bash
26+
27+
- name: Install i18n-helpers
28+
run: cargo install mdbook-i18n-helpers --locked --version '${{ steps.mdbook-i8n-helpers-version.outputs.MDBOOK_I8N_HELPERS_VERSION }}'
29+
shell: bash

.github/workflows/lint.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lint Markdown
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
style:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- uses: dprint/[email protected]

.github/workflows/publish.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy mdBook sites to GH Pages
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
# Allow one concurrent deployment
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: true
17+
18+
env:
19+
CARGO_TERM_COLOR: always
20+
# TODO: Update the language picker in index.hbs to link new languages.
21+
# TODO: As long as https://github.com/google/mdbook-i18n-helpers/issues/12 is not implemented, yet.
22+
# TODO: Activate when first translation is available
23+
# These are the languages in addition to 'en', which is the main language
24+
# LANGUAGES: xx
25+
26+
jobs:
27+
publish:
28+
environment:
29+
name: github-pages
30+
url: ${{ steps.deployment.outputs.page_url }}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
36+
- name: Setup Rust cache
37+
uses: ./.github/workflows/setup-rust-cache
38+
39+
- name: Install mdbook
40+
uses: ./.github/workflows/install-mdbook
41+
42+
- name: Build course in English
43+
run: mdbook build -d book
44+
45+
# TODO: Activate when first translation is available
46+
# - name: Build all translations
47+
# run: |
48+
# for po_lang in ${{ env.LANGUAGES }}; do
49+
# echo "::group::Building $po_lang translation"
50+
# MDBOOK_BOOK__LANGUAGE=$po_lang \
51+
# MDBOOK_OUTPUT__HTML__SITE_URL=/patterns/$po_lang/ \
52+
# mdbook build -d book/$po_lang
53+
# echo "::endgroup::"
54+
# done
55+
56+
- name: Setup Pages
57+
id: pages
58+
uses: actions/configure-pages@v3
59+
60+
- name: Upload artifact
61+
uses: actions/upload-pages-artifact@v1
62+
with:
63+
path: ./book
64+
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/deploy-pages@v2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Setup Rust cache
2+
3+
description: Configure the rust-cache workflow.
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Setup Rust cache
9+
uses: Swatinem/rust-cache@v2
10+
with:
11+
prefix-key: v1

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ idioms and other explanations. It is a compilation of collective (sometimes
77
implicit) knowledge as well as experiences that have emerged through
88
collaborative work.
99

10-
The patterns described here are __not rules__, but should be taken as
10+
The patterns described here are **not rules**, but should be taken as
1111
guidelines for writing idiomatic code in Rust. We are collecting Rust patterns
1212
in this book so people can learn the tradeoffs between Rust idioms and use them
1313
properly in their own code.

book.toml

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@ authors = ["the rust-unofficial authors"]
44
description = "A catalogue of Rust design patterns, anti-patterns and idioms"
55
language = "en"
66
multilingual = false
7-
src = "."
7+
src = "src"
88

99
[build]
1010
create-missing = false
11+
extra-watch-dirs = ["po", "third_party"]
12+
13+
[preprocessor.gettext]
14+
after = ["links"]
1115

1216
[rust]
1317
edition = "2018"
1418

1519
[output.html]
20+
curly-quotes = true
1621
default-theme = "rust"
1722
site-url = "/patterns/"
1823
git-repository-url = "https://github.com/rust-unofficial/patterns"
1924
git-repository-icon = "fa-github"
2025
edit-url-template = "https://github.com/rust-unofficial/patterns/edit/main/{path}"
26+
additional-css = ["./language-picker.css"]
27+
additional-js = ["./third_party/mdbook/book.js"]
28+
29+
[output.html.fold]
30+
enable = true
31+
level = 1
32+
33+
[output.html.playground]
34+
editable = false
2135

2236
# [output.linkcheck] # enable the "mdbook-linkcheck" renderer, disabled due to gh-actions

dprint.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"lineWidth": 80,
3+
"markdown": {},
4+
"includes": [
5+
"**/*.{md}"
6+
],
7+
"excludes": [],
8+
"plugins": [
9+
"https://plugins.dprint.dev/markdown-0.15.2.wasm"
10+
]
11+
}

language-picker.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#language-list {
2+
left: auto;
3+
right: 10px;
4+
}
5+
6+
#language-list a {
7+
color: inherit;
8+
}

0 commit comments

Comments
 (0)