Skip to content

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

@mootari

Description

@mootari

Following up from apache/arrow-js#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions