Skip to content
Merged
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
27 changes: 25 additions & 2 deletions tools/example-showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ weight = {}
let _ = fs::create_dir_all(&example_path);

let code_path = example_path.join(Path::new(&to_show.path).file_name().unwrap());
let _ = fs::copy(&to_show.path, &code_path);
let code = fs::read_to_string(&to_show.path).unwrap();
let (docblock, code) = split_docblock_and_code(&code);
let _ = fs::write(&code_path, code);

let mut example_index = File::create(example_path.join("index.md")).unwrap();
example_index
Expand All @@ -565,7 +567,10 @@ code_path = \"content/examples{}/{}\"
shader_code_paths = {:?}
github_code_path = \"{}\"
header_message = \"Examples ({})\"
+++",
+++

{}
",
to_show.name,
match api {
WebApi::Webgpu => "-webgpu",
Expand Down Expand Up @@ -603,6 +608,7 @@ header_message = \"Examples ({})\"
WebApi::Webgpu => "WebGPU",
WebApi::Webgl2 => "WebGL2",
},
docblock,
)
.as_bytes(),
)
Expand Down Expand Up @@ -723,6 +729,23 @@ header_message = \"Examples ({})\"
}
}

fn split_docblock_and_code(code: &str) -> (String, &str) {
let mut docblock_lines = Vec::new();
let mut code_byte_start = 0;

for line in code.lines() {
if line.starts_with("//!") {
docblock_lines.push(line.trim_start_matches("//!").trim());
} else if !line.trim().is_empty() {
break;
}

code_byte_start += line.len() + 1;
}

(docblock_lines.join("\n"), &code[code_byte_start..])
}

fn parse_examples() -> Vec<Example> {
let manifest_file = fs::read_to_string("Cargo.toml").unwrap();
let manifest = manifest_file.parse::<DocumentMut>().unwrap();
Expand Down