Skip to content

Commit

Permalink
Fix type link for internal static doc
Browse files Browse the repository at this point in the history
Summary:
# Background
For internal static doc, our doc is prefix with `https://www.internalfb.com/intern/staticdocs/buck2/`. Since we use `<a href = /path/to/type`, it will show 404 for it
 {F1950799844}

# This diff
Based on the Docusaurus's doc, it recommend using `<Link>` tag.
https://docusaurus.io/docs/api/misc/docusaurus/eslint-plugin/no-html-links
It needs us `import Link from 'docusaurus/Link`, so we need use `.mdx` instead of `.md` here.

According to the doc: https://docusaurus.io/docs/docusaurus-core#link, `Link` will apply base url for it. It will solve our problem
 {F1950829794}

Reviewed By: JakobDegen

Differential Revision: D65288103

fbshipit-source-id: ffb9b8df3f23b56fd9ff01ea9b3a3777bb6b2098
  • Loading branch information
Nero5023 authored and facebook-github-bot committed Oct 31, 2024
1 parent cc11a3f commit 4225132
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion starlark/src/docs/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn render_function_prototype(
// example:
// <pre class="language-python">
// <code>
// def soome_function() -> <a href="/path/to/type">Artifact</a>
// def soome_function() -> <Link to="/path/to/type">Artifact</Link>
// </code>
//</pre>
fn render_code_block(contents: &str, render_config: &TypeRenderConfig) -> String {
Expand Down
8 changes: 7 additions & 1 deletion starlark/src/docs/multipage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,19 @@ struct PageRender<'a> {

impl<'a> PageRender<'a> {
fn render_markdown(&self, render_config: &TypeRenderConfig) -> String {
match self.page {
let content = match self.page {
DocPageRef::Module(doc_module) => {
doc_module.render_markdown_page_for_multipage_render(&self.name, render_config)
}
DocPageRef::Type(doc_type) => {
doc_type.render_markdown_page_for_multipage_render(&self.name, render_config)
}
};
match render_config {
TypeRenderConfig::Default => content,
TypeRenderConfig::LinkedType { ty_to_path_map: _ } => {
format!("{}\n\n{}", "import Link from '@docusaurus/Link';", content)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# STARLARK_RUST_REGENERATE_GOLDEN_TESTS=1 cargo test -p starlark --lib
# ```

import Link from '@docusaurus/Link';

# Magic

<pre class="language-python"><code>def Magic(a1: int, a2: int = ..., step: int = 1, /) -> str</code></pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# STARLARK_RUST_REGENERATE_GOLDEN_TESTS=1 cargo test -p starlark --lib
# ```

import Link from '@docusaurus/Link';

# Obj

These are where the module docs go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# STARLARK_RUST_REGENERATE_GOLDEN_TESTS=1 cargo test -p starlark --lib
# ```

import Link from '@docusaurus/Link';

# globals

## MAGIC
Expand Down Expand Up @@ -43,7 +45,7 @@ The string 'func1'
b: int,
*,
c: int,
) -> <a href="/path/to/Magic">magic</a></code></pre>
) -> <Link to="/path/to/Magic">magic</Link></code></pre>

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# STARLARK_RUST_REGENERATE_GOLDEN_TESTS=1 cargo test -p starlark --lib
# ```

import Link from '@docusaurus/Link';

# submod

## new\_obj

<pre class="language-python"><code>def new_obj() -> <a href="/path/to/Obj">obj</a></code></pre>
<pre class="language-python"><code>def new_obj() -> <Link to="/path/to/Obj">obj</Link></code></pre>

---

Expand Down
2 changes: 1 addition & 1 deletion starlark/src/typing/starlark_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl TyStarlarkValue {
if let Some(link_path) =
ty_to_path_map.get(&Ty::basic(TyBasic::StarlarkValue(self.dupe())))
{
write!(f, "<a href=\"{link_path}\">{type_name}</a>")
write!(f, "<Link to=\"{link_path}\">{type_name}</Link>")
} else {
write!(f, "{}", type_name)
}
Expand Down

0 comments on commit 4225132

Please sign in to comment.