Skip to content

Commit 0bf7964

Browse files
committed
Add record fields
1 parent 6430d27 commit 0bf7964

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

docs/components/record.astro

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
import { micromark } from "micromark";
3+
const { name, items, typesInOwnModule } = Astro.props;
4+
---
5+
6+
<h4>Record fields</h4>
7+
{
8+
items.map((item) => {
9+
const documentation =
10+
item.docstrings && micromark(item.docstrings.join("\n"));
11+
12+
return (
13+
<div class="record_field">
14+
<h5 id={`${name}_${item.name}`}>{item.name}</h5>
15+
<div class="type">
16+
{typesInOwnModule.has(item.signature) ? (
17+
<a href={`#${item.signature}`}>{item.signature}</a>
18+
) : (
19+
item.signature
20+
)}
21+
</div>
22+
{documentation && <div class="doc" set:html={documentation} />}
23+
</div>
24+
);
25+
})
26+
}
27+
28+
<style>
29+
.record_field {
30+
display: grid;
31+
grid-template-rows: repeat(2, auto);
32+
grid-template-columns: repeat(2, 1fr);
33+
gap: 0.5rem;
34+
35+
border-bottom: 1px solid var(--sl-color-gray-7);
36+
37+
& .type {
38+
justify-self: end;
39+
color: var(--sl-color-accent-low);
40+
}
41+
42+
& .doc {
43+
padding-bottom: 0.5rem;
44+
grid-column: 1 / -1;
45+
grid-row: 2;
46+
}
47+
}
48+
</style>

docs/pages/apidocs/[API].astro

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { apiModules, getDoc } from "./utils";
33
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
44
import { Code } from "@astrojs/starlight/components";
55
import { micromark } from "micromark";
6+
import Record from "../../components/record.astro";
67
78
export async function getStaticPaths() {
89
return apiModules.map((apiModule) => {
@@ -15,6 +16,10 @@ export async function getStaticPaths() {
1516
});
1617
}
1718
19+
function showRecord(details) {
20+
return details && details.kind === "record" && details.items.length > 0;
21+
}
22+
1823
const { moduleName, filePath } = Astro.props;
1924
2025
const docInfo = await getDoc(filePath);
@@ -29,9 +34,12 @@ const types = docInfo.items
2934
name: type.name,
3035
documentation,
3136
signature: type.signature,
37+
detail: type.detail,
3238
};
3339
});
3440
41+
const typesInOwnModule = new Set(types.map((t) => t.name));
42+
3543
const typeHeadings = types.map((type) => ({
3644
depth: 3,
3745
slug: type.name,
@@ -61,6 +69,13 @@ const headings = [
6169
<h3 id={type.name}>{type.name}</h3>
6270
<div set:html={type.documentation} />
6371
<Code lang="ReScript" code={type.signature} />
72+
{showRecord(type.detail) ? (
73+
<Record
74+
name={type.name}
75+
typesInOwnModule={typesInOwnModule}
76+
{...type.detail}
77+
/>
78+
) : null}
6479
</div>
6580
))
6681
}

docs/styles/theme.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ https://github.com/withastro/starlight/blob/main/packages/starlight/style/props.
88
https://github.com/rescript-lang/rescript-lang.org/blob/4e4f9520f6fc7a0376db82a0a6db52211e8a8187/tailwind.config.mjs#L13
99
*/
1010

11+
@media (prefers-reduced-motion: no-preference) {
12+
html {
13+
scroll-behavior: smooth; /* Enables smooth scrolling for users without motion sensitivity */
14+
}
15+
}
16+
1117
:root[data-theme="light"],
1218
[data-theme="light"] ::backdrop {
1319
--sl-color-accent-low: #4a0f14;

0 commit comments

Comments
 (0)