arrow-site icon indicating copy to clipboard operation
arrow-site copied to clipboard

[Website] Inject source links into generated legacy JS API docs

Open mootari opened this issue 7 months ago • 2 comments

Following up from https://github.com/apache/arrow-js/issues/180

Rationale

Starting from version 17.0.0 the generated TypeDoc API docs no longer link any "Defined in ..." references to their GitHub source. Additionally, arrow-js has since been moved out of the monorepo but didn't migrate any version tags, making it more challenging for developers to find the sources for older versions.

npm stats show that versions before 20.0.0 still see widespread use (e.g., duckdb-wasm 1.29.0 references apache-arrow 17.0.0).

Suggested solution

All of the affected lines in the markup follow a consistent pattern. We can therefore simply inject the links into the already generated markup instead of having to fix the TypeDoc configuration and rebuilding the docs.

Example:

- <li>Defined in builder.ts:102</li>
+ <li>Defined in builder.ts:102<a href="https://github.com/apache/arrow/tree/apache-arrow-17.0.0/js/src/builder.ts#L102">builder.ts:102</a></li>

Shell script to apply the changes:

add-source-links()
{
  local docs_path="$1"
  local base_url="$2"
  find "$docs_path" \
    -name '*.html' \
    -exec sed -Ei '' 's'';<li>Defined in (([^<]+):([0-9]+))</li>;<li>Defined in <a href="'"$base_url"'\2#L\3">\1</a></li>;g' {} +  
}

add-source-links docs/17.0/js 'https://github.com/apache/arrow/tree/apache-arrow-17.0.0/js/src/'
add-source-links docs/18.0/js 'https://github.com/apache/arrow/tree/apache-arrow-18.0.0/js/src/'
add-source-links docs/18.1/js 'https://github.com/apache/arrow/tree/apache-arrow-18.1.0/js/src/'
add-source-links docs/19.0/js 'https://github.com/apache/arrow/tree/apache-arrow-19.0.0/js/src/'
add-source-links docs/js 'https://github.com/apache/arrow/tree/apache-arrow-20.0.0/js/src/'

Note that -exec sed -Ei '' 's… is macOS specific and may need to be changed to -exec sed -Ei 's… on other systems.

mootari avatar Jul 05 '25 11:07 mootari

@kou @amoeba To double-check before I file a PR: do I still have the go-ahead for the suggested solution?

mootari avatar Jul 27 '25 12:07 mootari

Yes.

kou avatar Jul 28 '25 00:07 kou