Skip to content

Commit 429d90f

Browse files
feat(examples): add rust-doc example
1 parent bcf6698 commit 429d90f

17 files changed

Lines changed: 298 additions & 4 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ coverage/
1212
_readthedocs/
1313
build/
1414
dist/
15+
target/
1516
lizardbyte-shared-web*.tgz

.readthedocs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ build:
66
nodejs: "22"
77
python: "3.13"
88
ruby: "3.3"
9+
rust: "1.91"
910
commands:
1011
- 'echo "output directory: ${READTHEDOCS_OUTPUT}html"'
1112
# shared-web build
@@ -26,5 +27,8 @@ build:
2627
- cd examples/sphinx && npm ci # we need to include scripts for postinstall actions
2728
- cd examples/sphinx && npm run build
2829
- cd examples/sphinx && npm run lint
30+
# rustdoc example build
31+
- cd examples/rustdoc && npm ci --ignore-scripts
32+
- cd examples/rustdoc && npm run build
2933
# debug output
3034
- cd ${READTHEDOCS_OUTPUT}html && ls -la -R

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default [
99
"coverage/**",
1010
"dist/**",
1111
"docs/**", // generated JSDoc output
12+
"examples/**/build/**", // generated example output
1213
],
1314
},
1415
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
rustdocflags = [
3+
"--html-after-content",
4+
"rustdoc/shared-web.html",
5+
]

examples/rustdoc/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rustdoc/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "shared-web-rustdoc-example"
3+
version = "0.0.0"
4+
edition = "2021"
5+
description = "Example use of @lizardbyte/shared-web in rustdoc html."
6+
license = "AGPL-3.0-only"
7+
publish = false
8+
exclude = [
9+
"build",
10+
"node_modules",
11+
]
12+
13+
[lib]
14+
name = "shared_web_rustdoc_example"
15+
path = "src/lib.rs"

examples/rustdoc/package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rustdoc/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "shared-web-rustdoc-example",
3+
"version": "0.0.0",
4+
"description": "Example use of @lizardbyte/shared-web in rustdoc html.",
5+
"dependencies": {
6+
"@lizardbyte/shared-web": "file:../.."
7+
},
8+
"scripts": {
9+
"build": "node rustdoc/build.js"
10+
}
11+
}

examples/rustdoc/rustdoc/build.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require('node:fs');
2+
const path = require('node:path');
3+
const { spawnSync } = require('node:child_process');
4+
5+
const exampleDir = path.resolve(__dirname, '..');
6+
const readTheDocsOutput = process.env.READTHEDOCS_OUTPUT ?
7+
path.resolve(process.env.READTHEDOCS_OUTPUT) :
8+
path.join(exampleDir, 'build');
9+
const targetDir = path.join(readTheDocsOutput, 'html', 'rustdoc');
10+
const docDir = path.join(targetDir, 'doc');
11+
const sharedWebDist = path.join(exampleDir, 'node_modules', '@lizardbyte', 'shared-web', 'dist');
12+
13+
const cargoResult = spawnSync('cargo', ['doc', '--no-deps', '--target-dir', targetDir], {
14+
stdio: 'inherit',
15+
});
16+
17+
if (cargoResult.status !== 0) {
18+
process.exit(cargoResult.status || 1);
19+
}
20+
21+
fs.mkdirSync(docDir, { recursive: true });
22+
23+
[
24+
'crowdin.js',
25+
'crowdin-rustdoc-css.css',
26+
].forEach((asset) => {
27+
fs.copyFileSync(path.join(sharedWebDist, asset), path.join(docDir, asset));
28+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--LIZARDBYTE/SHARED-WEB START-->
2+
<script>
3+
(function() {
4+
const rustdocVars = document.querySelector('meta[name="rustdoc-vars"]');
5+
const rootPath = rustdocVars ? rustdocVars.dataset.rootPath : '';
6+
7+
const stylesheet = document.createElement('link');
8+
stylesheet.rel = 'stylesheet';
9+
stylesheet.href = rootPath + 'crowdin-rustdoc-css.css';
10+
document.head.appendChild(stylesheet);
11+
12+
const crowdin = document.createElement('script');
13+
crowdin.src = rootPath + 'crowdin.js';
14+
crowdin.onload = function() {
15+
globalThis.initCrowdIn('LizardByte-docs', 'rustdoc');
16+
};
17+
document.head.appendChild(crowdin);
18+
}());
19+
</script>
20+
<!--LIZARDBYTE/SHARED-WEB END-->

0 commit comments

Comments
 (0)