Skip to content

Commit

Permalink
Update Docusaurus 3 (#111)
Browse files Browse the repository at this point in the history
* remove duplicated arrow + custom style for donate button
* fix hot reload
More info at facebook/docusaurus#9698
* update to yarn 4 + update math dependencies
deps remark-math and rehype-katex updated
* fix crossplatform inject
* more thorough ci test, which now can run `yarn build`
  • Loading branch information
Vrixyz authored Aug 6, 2024
1 parent a206398 commit b215e48
Show file tree
Hide file tree
Showing 11 changed files with 26,989 additions and 10,503 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ env:
CARGO_TERM_COLOR: always

jobs:
check-injection:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run injection script locally
run: find docs/user_guides/templates/ -type f -print0 | OUTPUT_FOLDER=docs/user_guides/templates_injected xargs -0 ./inject_code_in_user_guides.sh
- name: User guides generation
run: ./generate_user_guides.sh
- name: yarn install
run: corepack enable && yarn
- name: yarn build
run: PUBLISH_MODE=1 yarn build

test-code-snippets-rust:
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ yarn-error.log*

build

## For yarn 4: See https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Ignore these because they are generated automatically from docs/user_guides/templates
docs/user_guides/rust
docs/user_guides/bevy_plugin
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
35 changes: 21 additions & 14 deletions docs-examples/inject_file/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ pub struct InjectError<'a> {
}

fn injected(source_text: &str, get_path: fn(&str) -> String) -> Result<String, InjectError> {
let source_text = &source_text.replace("\r\n", "\n");
let re = Regex::new(r"<load.*>").unwrap();
let total_to_inject = re.find_iter(source_text).count();
let mut injected_count = 0;
// Regex to find "<load" tags and capture their info (path + marker)
let re = Regex::new(r"<load path='(.*)'.*marker='(.*)'.*>[\r\n|\n]?").unwrap();
let re = Regex::new(r"<load path='(.*)'.*marker='(.*)'.*>\n?").unwrap();

let mut error = InjectError {
result: None,
Expand All @@ -85,12 +86,12 @@ fn injected(source_text: &str, get_path: fn(&str) -> String) -> Result<String, I
error.errors.push(ErrorType::IncorrectPath(path));
return "".to_string();
};

let to_inject = to_inject.replace("\r\n", "\n");
// Regex to find the markers inside comments, and only print what's inside
// FIXME: I think we should just paste all the inside,
// and then remove all "// DOCUSAURUS*"" lines, to allow reuse of a same file.
let regex = format!(
r"// DOCUSAURUS: {} start(?:\r\n|\n)((?:\s|.)*)\s+\/\/ DOCUSAURUS: {} stop",
r"// DOCUSAURUS: {} start\n((?:\s|.)*)\s+\/\/ DOCUSAURUS: {} stop",
infos[1], infos[1]
);
let re = Regex::new(&regex).unwrap();
Expand All @@ -115,15 +116,16 @@ fn injected(source_text: &str, get_path: fn(&str) -> String) -> Result<String, I
filepath: infos[0].to_string(),
}));
}
to_keep.join("")
let mut result = to_keep.join("");
result.push('\n');
result
});
if (injected_count + error.errors.len()) != total_to_inject {
error.errors.push(ErrorType::IncorrectTag);
}
if 0 < error.errors.len() {
return Err(error);
}
let result = result.replace("\r\n", "\n");
let re = Regex::new(r"(.*\/\/ DOCUSAURUS:.*\n)").unwrap();
let result = re.replace_all(&result, |_: &Captures| "").to_string();
Ok(result)
Expand Down Expand Up @@ -198,10 +200,11 @@ fn nest_removal() {

// Trimming end for cross platform, on windows I had \r finishing result.
assert_eq!(
result.expect("This should not error out").trim_end(),
result.expect("This should not error out"),
"correct data nest1
correct data nested
correct data nest2"
correct data nest2
"
);
}

Expand All @@ -212,15 +215,17 @@ fn indent_removal_simple() {
let result = remove_indent(
" correct data indented 1
correct data indented more
correct data indented 2",
correct data indented 2
",
);

// Trimming end for cross platform, on windows I had \r finishing result.
assert_eq!(
result.expect("This should not error out").trim_end(),
result.expect("This should not error out"),
"correct data indented 1
correct data indented more
correct data indented 2"
correct data indented 2
"
);
}

Expand Down Expand Up @@ -286,8 +291,10 @@ fn simple_marker_error() {
);

// Trimming end for cross platform, on windows I had \r finishing result.
assert!(matches!(
&result.expect_err("This should error out").errors[0],
IncorrectMarker
));
match &result.expect_err("This should error out").errors[0] {
ErrorType::IncorrectMarker(_) => {}
invalid_value => {
panic!("unexpected error type: {:?}", invalid_value);
}
}
}
29 changes: 15 additions & 14 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
const math = require('remark-math')
const katex = require('rehype-katex')

module.exports = {
const config = {
title: 'Rapier',
tagline: 'Fast 2D and 3D physics engine for the Rust programming language.',
url: 'https://rapier.rs',
baseUrl: '/',
onBrokenLinks: 'error', // 'throw',
onBrokenLinks: 'throw',
favicon: 'img/favicon.png',
organizationName: 'dimforge', // Usually your GitHub org/user name.
projectName: 'rapier', // Usually your repo name.
themeConfig: {
algolia: {
apiKey: '2fb2392fe420e3f9cd94004bda27a775',
appId: 'rapier',
indexName: 'rapier',
},
prism: {
theme: require('prism-react-renderer/themes/github'),
theme: require('prism-react-renderer').themes.github,
additionalLanguages: ['toml', 'rust'],
},
// announcementBar: {
Expand Down Expand Up @@ -44,13 +45,11 @@ module.exports = {
items: [
{
href: 'https://rapier.rs/demos2d/index.html', // FIXME: should depend on the base url.
label: '2D Demos ↪',
position: 'left',
label: '2D Demos',
},
{
href: 'https://rapier.rs/demos3d/index.html', // FIXME: should depend on the base url.
label: '3D Demos ↪',
position: 'left',
label: '3D Demos',
}
],
},
Expand All @@ -62,18 +61,18 @@ module.exports = {
},
{
href: 'https://dimforge.com/blog',
label: 'Blog',
label: 'Blog',
position: 'left',
},
{
href: 'https://github.com/sponsors/dimforge',
label: 'Donate ♥',
value: '<a class="header-button-donate" href="https://github.com/sponsors/dimforge" target="_blank" rel="noopener noreferrer">Donate ♥</a>',
className: 'header-button-donate',
position: 'right',
className: 'header-button-donate'
type: 'html'
},
{
href: 'https://dimforge.com',
label: 'Dimforge',
label: 'Dimforge',
position: 'right',
},
{
Expand Down Expand Up @@ -101,11 +100,11 @@ module.exports = {
to: 'docs/',
},
{
label: 'Demos 2D',
label: 'Demos 2D',
href: 'https://rapier.rs/demos2d/index.html',
},
{
label: 'Demos 3D',
label: 'Demos 3D',
href: 'https://rapier.rs/demos3d/index.html',
},
],
Expand Down Expand Up @@ -182,3 +181,5 @@ module.exports = {
'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css'
]
};

export default config;
42 changes: 25 additions & 17 deletions generate_user_guides.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#!/bin/bash
set -v

if [ gsed -v ]; then
gsed=gsed
else
# Hopefully installed sed is the gnu one.
# note: aliases work poorly with xargs.
gsed=sed
fi

mkdir -p docs/user_guides/rust/
mkdir -p docs/user_guides/bevy_plugin/
mkdir -p docs/user_guides/javascript/
Expand All @@ -12,28 +20,28 @@ cp -r docs/user_guides/templates_injected/* docs/user_guides/bevy_plugin/.
cp -r docs/user_guides/templates_injected/* docs/user_guides/javascript/.

find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 gawk -i inplace -v RS='<rapier>[^<]*</rapier>' -v ORS= '1'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 sed -i '/<rapier>/,/<\/rapier>/d'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 $gsed -i '/<rapier>/,/<\/rapier>/d'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 gawk -i inplace -v RS='<js>[^<]*</js>' -v ORS= '1'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 sed -i '/<js>/,/<\/js>/d'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 sed -i 's\<bevy>\\g'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 sed -i 's\</bevy>\\g'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 sed -i 's\<notjs>\\g'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 sed -i 's\</notjs>\\g'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 $gsed -i '/<js>/,/<\/js>/d'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 $gsed -i 's\<bevy>\\g'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 $gsed -i 's\</bevy>\\g'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 $gsed -i 's\<notjs>\\g'
find docs/user_guides/bevy_plugin/ -type f -print0 | xargs -0 $gsed -i 's\</notjs>\\g'

find docs/user_guides/rust/ -type f -print0 | xargs -0 gawk -i inplace -v RS='<bevy>[^<]*</bevy>' -v ORS= '1'
find docs/user_guides/rust/ -type f -print0 | xargs -0 sed -i '/<bevy>/,/<\/bevy>/d'
find docs/user_guides/rust/ -type f -print0 | xargs -0 $gsed -i '/<bevy>/,/<\/bevy>/d'
find docs/user_guides/rust/ -type f -print0 | xargs -0 gawk -i inplace -v RS='<js>[^<]*</js>' -v ORS= '1'
find docs/user_guides/rust/ -type f -print0 | xargs -0 sed -i '/<js>/,/<\/js>/d'
find docs/user_guides/rust/ -type f -print0 | xargs -0 sed -i 's\<rapier>\\g'
find docs/user_guides/rust/ -type f -print0 | xargs -0 sed -i 's\</rapier>\\g'
find docs/user_guides/rust/ -type f -print0 | xargs -0 sed -i 's\<notjs>\\g'
find docs/user_guides/rust/ -type f -print0 | xargs -0 sed -i 's\</notjs>\\g'
find docs/user_guides/rust/ -type f -print0 | xargs -0 $gsed -i '/<js>/,/<\/js>/d'
find docs/user_guides/rust/ -type f -print0 | xargs -0 $gsed -i 's\<rapier>\\g'
find docs/user_guides/rust/ -type f -print0 | xargs -0 $gsed -i 's\</rapier>\\g'
find docs/user_guides/rust/ -type f -print0 | xargs -0 $gsed -i 's\<notjs>\\g'
find docs/user_guides/rust/ -type f -print0 | xargs -0 $gsed -i 's\</notjs>\\g'

find docs/user_guides/javascript/ -type f -print0 | xargs -0 gawk -i inplace -v RS='<rapier>[^<]*</rapier>' -v ORS= '1'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 sed -i '/<rapier>/,/<\/rapier>/d'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 $gsed -i '/<rapier>/,/<\/rapier>/d'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 gawk -i inplace -v RS='<bevy>[^<]*</bevy>' -v ORS= '1'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 sed -i '/<bevy>/,/<\/bevy>/d'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 $gsed -i '/<bevy>/,/<\/bevy>/d'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 gawk -i inplace -v RS='<notjs>[^<]*</notjs>' -v ORS= '1'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 sed -i '/<notjs>/,/<\/notjs>/d'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 sed -i 's\<js>\\g'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 sed -i 's\</js>\\g'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 $gsed -i '/<notjs>/,/<\/notjs>/d'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 $gsed -i 's\<js>\\g'
find docs/user_guides/javascript/ -type f -print0 | xargs -0 $gsed -i 's\</js>\\g'
Loading

0 comments on commit b215e48

Please sign in to comment.