Skip to content

Conversation

sissbruecker
Copy link
Contributor

Description

Adds an Astro-based API docs website that is intended to replace the current iron-docs-viewer based one at some point.

Compared to the current one, it has the following benefits:

  • It's based on Astro and generates static HTML. That should make it more useful for search engines and AI tools. In comparison, the current API docs are basically an empty HTML page with a single custom element on it and AI assistants (at least GH Copilot) can't find any info on it when you pass them a URL.
  • It's still based on the Polymer analysis JSON, but instead of using the type annotations from the JSDoc it looks up types from the Typescript declaration files. It also inlines all custom type definitions used in a component (events, renderers, i18n objects) into the page for easier reference.
  • It generates static Markdown files as well, which are easier to process by AI tools. Each component page has a link to that MD file, as well as a copy button that allows to just copy+paste that MD as context into a prompt. Adding an index of these pages to comply with the llms.txt schema would also be possible.
  • Apart from that it has the usual affordances from Astro like a search function or theme switcher.

Type of change

  • Feature

function sanitizeDescription(description: string) {
// Fix links to other elements
description = description.replace(/#\/elements\//gu, '/elements/');
// Fix links to properties (e.g. #property-dataProvider to #dataprovider)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document fragments might need some work, I think there are some duplicates on some pages at the moment. Could be improved later IMO, would require figuring out how to customize these in Astro from within the Markdown file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean such duplicates? Or is it a different issue?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All headings in the document are linkable with a document fragment (e.g. #selected-item). For those there can be duplicates. For example the GridPro page has a heading for the dataProvider property, and then there is a heading for the DataProvider type. If some other page would link to one of those headings you might not end up at the correct one. Doesn't seem to be a problem at the moment though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, the new 11ty based version handles this by changing the second heading to #dataprovider-1.

}

// Properties
const publicProperties = filterPublicApi(element.properties);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new API docs only show public APIs.

"build": "astro build",
"preview": "astro preview",
"astro": "astro",
"generate": "tsx generate.ts"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used tsx for now. Since Node 23 this works without, but we don't have that on CI servers yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This customizes the default page header to have buttons / links for the Markdown content.

loader: docsLoader(),
schema: docsSchema({
extend: z.object({
pageType: z.optional(z.string()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Customizes the page schema to add pageType. This is used to only render the Markdown button / links on element pages, but not on the index page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implements the type lookup from the TS declaration files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates the content for the Astro site based on analysis.json.

@vursen
Copy link
Contributor

vursen commented Aug 8, 2025

On some pages, there are duplicate event names that differ only by a hyphen, for example:

http://localhost:4321/elements/vaadin-app-layout/

@sissbruecker sissbruecker force-pushed the feat/astro-api-docs branch 2 times, most recently from 0c2f8a6 to 74fd771 Compare August 8, 2025 11:56
@sissbruecker
Copy link
Contributor Author

On some pages, there are duplicate event names that differ only by a hyphen

For some reason I added generation of property change events, I could have sworn some were missing from the JSON. But after double-checking that doesn't seem to be the case. So I removed that part of the generator. Looks like the number of events now line up between old and new API docs.

@web-padawan web-padawan changed the title feat: add api docs package chore: add api-docs package Aug 12, 2025
Copy link

@web-padawan web-padawan merged commit 858c565 into main Aug 12, 2025
9 checks passed
@web-padawan web-padawan deleted the feat/astro-api-docs branch August 12, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants