-
Notifications
You must be signed in to change notification settings - Fork 16
feat(docs/ensnode.io): Add API Reference #1805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
b0e19d5
3376bf1
b10469e
028dc20
209bf29
fc1d687
c2ed645
306e78e
b917985
b433a3a
633d017
9d8c72e
086d732
834f8cf
dae5c3b
63cf42b
17c8ff1
a56eef9
b44776b
f51e879
a9996e4
02fa7e8
14ac925
c62e21f
ada1ea8
0c7e734
39f0ff8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,93 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
notrab marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <starlight-toc data-min-h="2" data-max-h="3"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <nav aria-labelledby="scalar__on-this-page"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <h2 id="scalar__on-this-page">On this page</h2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ul class="scalar-toc-list"></ul> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </nav> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </starlight-toc> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function buildToc() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const list = document.querySelector('.scalar-toc-list'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!list) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const headings = document.querySelectorAll('h2.section-header-label[id]'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (headings.length === 0) return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| list.innerHTML = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headings.forEach((h2) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const li = document.createElement('li'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const a = document.createElement('a'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| a.href = `#${h2.id}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const span = document.createElement('span'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| span.textContent = h2.textContent?.trim() ?? ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| a.appendChild(span); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| li.appendChild(a); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Find h3s that belong to this h2's section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const section = h2.closest('.section'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (section) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const h3s = section.querySelectorAll('h3[id]'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (h3s.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const subList = document.createElement('ul'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| h3s.forEach((h3) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const subLi = document.createElement('li'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const subA = document.createElement('a'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subA.href = `#${h3.id}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const subSpan = document.createElement('span'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subSpan.textContent = h3.textContent?.trim() ?? ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subA.appendChild(subSpan); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subLi.appendChild(subA); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subList.appendChild(subLi); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| li.appendChild(subList); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| list.appendChild(li); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Scalar renders async, so observe for headings to appear | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!buildToc()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const observer = new MutationObserver(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (buildToc()) observer.disconnect(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| observer.observe(document.body, { childList: true, subtree: true }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+57
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Scalar renders async, so observe for headings to appear | |
| if (!buildToc()) { | |
| const observer = new MutationObserver(() => { | |
| if (buildToc()) observer.disconnect(); | |
| }); | |
| observer.observe(document.body, { childList: true, subtree: true }); | |
| function getScalarObservationRoot() { | |
| return document.querySelector('main'); | |
| } | |
| // Scalar renders async, so observe for headings to appear | |
| if (!buildToc()) { | |
| const observationRoot = getScalarObservationRoot(); | |
| if (observationRoot) { | |
| const observer = new MutationObserver(() => { | |
| if (buildToc()) cleanup(); | |
| }); | |
| const timeoutId = window.setTimeout(() => { | |
| cleanup(); | |
| }, 10000); | |
| function cleanup() { | |
| observer.disconnect(); | |
| window.clearTimeout(timeoutId); | |
| window.removeEventListener('pagehide', cleanup); | |
| } | |
| window.addEventListener('pagehide', cleanup, { once: true }); | |
| observer.observe(observationRoot, { childList: true, subtree: true }); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| --- | ||
| import Default from "@astrojs/starlight/components/TableOfContents.astro"; | ||
|
|
||
| import ScalarTableOfContents from "../molecules/ScalarTableOfContents.astro"; | ||
| import TelegramInvite from "../molecules/TelegramInvite.astro"; | ||
|
|
||
| const { starlightRoute } = Astro.locals; | ||
| const isApiReference = starlightRoute.slug === "ensapi/reference/api-reference"; | ||
| --- | ||
|
|
||
| <Default /> | ||
| {isApiReference ? <ScalarTableOfContents /> : <Default />} | ||
| <br /> | ||
| <TelegramInvite /> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||
| --- | ||||||||||||||||||||
| title: ENSApi API Reference | ||||||||||||||||||||
| description: Interactive API reference documentation for ENSApi endpoints. | ||||||||||||||||||||
| sidebar: | ||||||||||||||||||||
| label: API Reference | ||||||||||||||||||||
| tableOfContents: | ||||||||||||||||||||
| minHeadingLevel: 6 | ||||||||||||||||||||
| maxHeadingLevel: 6 | ||||||||||||||||||||
|
Comment on lines
+6
to
+8
|
||||||||||||||||||||
| --- | ||||||||||||||||||||
|
notrab marked this conversation as resolved.
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| import { ScalarComponent } from "@scalar/astro"; | ||||||||||||||||||||
| import openapiSpec from "@workspace/docs/docs.ensnode.io/ensapi-openapi.json"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <ScalarComponent | ||||||||||||||||||||
| configuration={{ | ||||||||||||||||||||
| content: openapiSpec, | ||||||||||||||||||||
|
Comment on lines
+12
to
+16
|
||||||||||||||||||||
| import openapiSpec from "@workspace/docs/docs.ensnode.io/ensapi-openapi.json"; | |
| <ScalarComponent | |
| configuration={{ | |
| content: openapiSpec, | |
| <ScalarComponent | |
| configuration={{ | |
| spec: { url: "/ensapi-openapi.json" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing so would (URL) mean we can't view in our preview deployments the upcoming API spec changes. Need to investigate the static asset path though... I assume this means just putting it in the public directory, instead of where it is now in the root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think not worth optimizing, is a-ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked to implement this last week but there is a lot more involved that would require changing the CI steps so we output the spec to the public directory. We could change the output directory of the generated spec (and what our CI check looks at), or copy on build to the public folder so we can use the url param of ScalarComponent. Both approaches are fine in my opinion.
I'm more inclined to follow option A to move the output directory to public so that it can be served from the docs site too, but I would do this in a separate PR. Which I can do next week @lightwalker-eth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description notes overriding Starlight’s
TwoColumnContentto always render the right sidebar column, but this integration’scomponentslist does not register aTwoColumnContentoverride and there’s no override file undersrc/components/overrides. If that override is required for the new reference page layout (e.g., keeping the right sidebar when TOC is disabled), it should be included here; otherwise the PR description should be updated to reflect the actual approach.