mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Add a base href root to docs links
This commit is contained in:
parent
98682d44ac
commit
d37e30560b
2 changed files with 41 additions and 10 deletions
|
@ -143,7 +143,7 @@ fn render_main_content(
|
|||
if should_render_entry {
|
||||
match entry {
|
||||
DocEntry::DocDef(doc_def) => {
|
||||
let mut href = String::new();
|
||||
let mut href = base_href();
|
||||
href.push('#');
|
||||
href.push_str(doc_def.name.as_str());
|
||||
|
||||
|
@ -239,11 +239,40 @@ fn html_node(tag_name: &str, attrs: Vec<(&str, &str)>, content: &str) -> String
|
|||
buf
|
||||
}
|
||||
|
||||
fn base_href() -> String {
|
||||
// e.g. "builtins/" in "https://roc-lang.org/builtins/Str"
|
||||
//
|
||||
// TODO make this a CLI flag to the `docs` subcommand instead of an env var
|
||||
match std::env::var("ROC_DOCS_URL_ROOT") {
|
||||
Ok(root_builtins_path) => {
|
||||
let mut href = String::with_capacity(root_builtins_path.len() + 64);
|
||||
|
||||
if !root_builtins_path.starts_with('/') {
|
||||
href.push('/');
|
||||
}
|
||||
|
||||
href.push_str(&root_builtins_path);
|
||||
|
||||
if !root_builtins_path.ends_with('/') {
|
||||
href.push('/');
|
||||
}
|
||||
|
||||
href
|
||||
}
|
||||
_ => {
|
||||
let mut href = String::with_capacity(64);
|
||||
|
||||
href.push('/');
|
||||
|
||||
href
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_name_and_version(name: &str, version: &str) -> String {
|
||||
let mut buf = String::new();
|
||||
let mut href = base_href();
|
||||
|
||||
let mut href = String::new();
|
||||
href.push('/');
|
||||
href.push_str(name);
|
||||
|
||||
buf.push_str(
|
||||
|
@ -255,7 +284,7 @@ fn render_name_and_version(name: &str, version: &str) -> String {
|
|||
.as_str(),
|
||||
);
|
||||
|
||||
let mut versions_href = String::new();
|
||||
let mut versions_href = base_href();
|
||||
|
||||
versions_href.push('/');
|
||||
versions_href.push_str(name);
|
||||
|
@ -285,8 +314,7 @@ fn render_sidebar<'a, I: Iterator<Item = (Vec<String>, &'a ModuleDocumentation)>
|
|||
let name = module.name.as_str();
|
||||
|
||||
let href = {
|
||||
let mut href_buf = String::new();
|
||||
href_buf.push('/');
|
||||
let mut href_buf = base_href();
|
||||
href_buf.push_str(name);
|
||||
href_buf
|
||||
};
|
||||
|
@ -718,12 +746,11 @@ fn doc_url<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
let mut url = String::new();
|
||||
let mut url = base_href();
|
||||
|
||||
// Example:
|
||||
//
|
||||
// module_name: "Str", ident: "join" => "/Str#join"
|
||||
url.push('/');
|
||||
url.push_str(module_name);
|
||||
url.push('#');
|
||||
url.push_str(ident);
|
||||
|
|
|
@ -22,7 +22,11 @@ rustc --version
|
|||
# We set RUSTFLAGS to -Awarnings to ignore warnings during this build,
|
||||
# because when building without "the" llvm feature (which is only ever done
|
||||
# for this exact use case), the result is lots of "unused" warnings!
|
||||
RUSTFLAGS=-Awarnings cargo run -p roc_cli --no-default-features docs compiler/builtins/docs/Bool.roc
|
||||
RUSTFLAGS=-Awarnings cargo run -p roc_cli --no-default-features docs compiler/builtins/docs/Str.roc
|
||||
#
|
||||
# We set ROC_DOCS_ROOT_DIR=builtins so that links will be generated relative to
|
||||
# "/builtins/" rather than "/" - which is what we want based on how the server
|
||||
# is set up to serve them.
|
||||
RUSTFLAGS=-Awarnings ROC_DOCS_URL_ROOT=builtins cargo run -p roc_cli --no-default-features docs compiler/builtins/docs/Bool.roc
|
||||
RUSTFLAGS=-Awarnings ROC_DOCS_URL_ROOT=builtins cargo run -p roc_cli --no-default-features docs compiler/builtins/docs/Str.roc
|
||||
mv generated-docs/ www/build/builtins
|
||||
popd
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue