-
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
base: main
Are you sure you want to change the base?
Changes from all commits
b0e19d5
3376bf1
b10469e
028dc20
209bf29
fc1d687
c2ed645
306e78e
b917985
b433a3a
633d017
9d8c72e
086d732
834f8cf
dae5c3b
63cf42b
17c8ff1
a56eef9
b44776b
f51e879
a9996e4
02fa7e8
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,102 @@ | ||
| --- | ||
| --- | ||
|
|
||
| <nav class="scalar-toc"> | ||
| <h2 class="scalar-toc-heading">On this page</h2> | ||
| <ul class="scalar-toc-list"></ul> | ||
| </nav> | ||
|
|
||
| <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}`; | ||
| a.textContent = h2.textContent?.trim() ?? ''; | ||
| 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'); | ||
| subList.className = 'scalar-toc-sublist'; | ||
| h3s.forEach((h3) => { | ||
| const subLi = document.createElement('li'); | ||
| const subA = document.createElement('a'); | ||
| subA.href = `#${h3.id}`; | ||
| subA.textContent = h3.textContent?.trim() ?? ''; | ||
| 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 }); | ||
| } | ||
| </script> | ||
|
|
||
| <style> | ||
| .scalar-toc { | ||
| padding: 1rem 0; | ||
| } | ||
|
|
||
| .scalar-toc-heading { | ||
| color: var(--sl-color-white); | ||
| font-size: var(--sl-text-xs); | ||
| font-weight: 600; | ||
| text-transform: uppercase; | ||
| letter-spacing: 0.05em; | ||
| padding-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .scalar-toc-list { | ||
| list-style: none; | ||
| padding: 0; | ||
| margin: 0; | ||
| border-inline-start: 1px solid var(--sl-color-hairline); | ||
| } | ||
|
|
||
| .scalar-toc-list li a { | ||
| display: block; | ||
| padding: 0.25rem 0 0.25rem 0.75rem; | ||
| color: var(--sl-color-gray-3); | ||
| font-size: var(--sl-text-xs); | ||
| text-decoration: none; | ||
| line-height: 1.5; | ||
| } | ||
|
|
||
| .scalar-toc-list li a:hover { | ||
| color: var(--sl-color-white); | ||
| } | ||
|
|
||
| .scalar-toc-sublist { | ||
| list-style: none; | ||
| padding: 0; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .scalar-toc-sublist li a { | ||
| padding-inline-start: 1.5rem; | ||
| } | ||
| </style> |
| 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,52 @@ | ||||||||||||||||||||
| --- | ||||||||||||||||||||
| title: ENSApi API Reference | ||||||||||||||||||||
| description: Interactive API reference documentation for ENSApi endpoints. | ||||||||||||||||||||
| sidebar: | ||||||||||||||||||||
| label: API Reference | ||||||||||||||||||||
| tableOfContents: | ||||||||||||||||||||
| minHeadingLevel: 6 | ||||||||||||||||||||
| maxHeadingLevel: 6 | ||||||||||||||||||||
| --- | ||||||||||||||||||||
notrab marked this conversation as resolved.
Show resolved
Hide 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.
PR description mentions the API reference page uses
tableOfContents: false, but this frontmatter setstableOfContentsto an options object (min/max heading level 6). If the intent is to disable Starlight TOC for this page, set it explicitly tofalse; if the object form is intentional as a workaround, please align the PR description (or add a short comment here explaining why).