Skip to content

Commit 2cd5f38

Browse files
authored
Update docs layout (#97)
1 parent 303e686 commit 2cd5f38

31 files changed

+1992
-756
lines changed

.eslintrc.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
2+
const path = require('node:path')
3+
14
/** @type {import('eslint').Linter.Config} */
25
const config = {
36
extends: [
@@ -9,6 +12,9 @@ const config = {
912
node: true,
1013
},
1114
ignorePatterns: ['dist', '*.njk'],
15+
parserOptions: {
16+
project: [path.resolve(__dirname, 'tsconfig.json')],
17+
},
1218
rules: {
1319
'@typescript-eslint/ban-types': 'off',
1420
'@typescript-eslint/lines-between-class-members': 'off',

docs/eleventy.config.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
/* eslint-disable @typescript-eslint/no-unsafe-call */
2-
31
import eleventyNavigationPlugin from '@11ty/eleventy-navigation'
42
import eleventyRemark from '@fec/eleventy-plugin-remark'
5-
import dedent from 'dedent'
63
import { rehype } from 'rehype'
74
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
85
import rehypeSlug from 'rehype-slug'
9-
import { remark } from 'remark'
106
import remarkDirective from 'remark-directive'
117

128
import { remarkDirectives } from './remark/directives.js'
139
import { remarkHeadings } from './remark/headings.js'
1410
import { remarkSample } from './remark/sample.js'
11+
import { rehypeTableOfContents } from './remark/table-of-contents.js'
1512

16-
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
13+
/** @param {import('@11ty/eleventy/UserConfig').default} eleventyConfig */
1714
export default async function config(eleventyConfig) {
1815
eleventyConfig.addPassthroughCopy({
1916
'src/assets/fonts': './assets/fonts',
@@ -23,32 +20,6 @@ export default async function config(eleventyConfig) {
2320
})
2421
eleventyConfig.addPassthroughCopy({ 'src/public': '.' })
2522

26-
eleventyConfig.addPairedShortcode(
27-
'navitem',
28-
(content, url, isSelected, isInactive) => {
29-
let tag = ''
30-
31-
if (isInactive) {
32-
tag = `<span class="px-3 py-2 relative block text-grey-400">${content}</span>`
33-
} else {
34-
let linkClass = [
35-
'px-3 py-2 transition-colors duration-200 relative block',
36-
isSelected && 'text-sky-700',
37-
!isSelected && 'hover:text-grey-900 text-grey-500',
38-
].join(' ')
39-
40-
tag = dedent`<a class="${linkClass}" href="${url}">
41-
<span class="rounded-md absolute inset-0 bg-sky-50 ${
42-
!isSelected && 'opacity-0'
43-
}"></span>
44-
<span class="relative">${content}</span>
45-
</a>`
46-
}
47-
48-
return `<li>${tag}</li>`
49-
},
50-
)
51-
5223
eleventyConfig.addPlugin(eleventyNavigationPlugin)
5324
eleventyConfig.addPlugin(eleventyRemark, {
5425
plugins: [
@@ -62,14 +33,25 @@ export default async function config(eleventyConfig) {
6233

6334
eleventyConfig.addTransform(
6435
'rehype',
65-
/** @param {string} content */ async (content, outputPath) => {
36+
/**
37+
* @param {string} content
38+
* @param {string} outputPath
39+
*/
40+
async (content, outputPath) => {
6641
let newContent = content
6742

6843
if (outputPath?.endsWith('.html')) {
6944
let result = await rehype()
7045
.use(rehypeSlug)
7146
.use(rehypeAutolinkHeadings, {
72-
test: (element, index, parent) => parent.tagName !== 'nav',
47+
test(element, index, parent) {
48+
return (
49+
parent?.type === 'element' &&
50+
parent?.tagName !== 'nav' &&
51+
element.tagName !== 'h1' &&
52+
element.tagName !== 'h5'
53+
)
54+
},
7355
properties: {
7456
class:
7557
'absolute ml-[-0.75em] md:ml-[-1em] pr-[0.5em] !no-underline !text-grey-400 opacity-0 group-hover:opacity-100',
@@ -88,6 +70,18 @@ export default async function config(eleventyConfig) {
8870
},
8971
)
9072

73+
eleventyConfig.addAsyncFilter(
74+
'toc',
75+
/** @param {string} content */ async (content) => {
76+
let output = await rehype()
77+
.data('settings', { fragment: true })
78+
.use(rehypeSlug)
79+
.use(rehypeTableOfContents)
80+
.process(content)
81+
return output.toString()
82+
},
83+
)
84+
9185
return {
9286
dir: {
9387
input: 'src',

docs/package.json

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,44 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"build": "eleventy --config=eleventy.config.js",
8-
"dev": "TAILWIND_MODE=watch eleventy --config=eleventy.config.js --serve"
7+
"build": "run-s build:*",
8+
"build:11ty": "npx @11ty/eleventy",
9+
"build:css": "npx @tailwindcss/cli -i ./src/assets/main.css -o ./dist/assets/styles.css",
10+
"build:old": "eleventy --config=eleventy.config.js",
11+
"dev": "run-p start:*",
12+
"dev:old": "TAILWIND_MODE=watch npx @11ty/eleventy --config=eleventy.config.js --serve",
13+
"start:11ty": "npx @11ty/eleventy --serve --quiet",
14+
"start:css": "npx @tailwindcss/cli -i ./src/assets/main.css -o ./dist/assets/styles.css --watch"
915
},
1016
"devDependencies": {
11-
"@11ty/eleventy": "3.0.0",
12-
"@11ty/eleventy-navigation": "0.3.5",
13-
"@11ty/eleventy-plugin-syntaxhighlight": "5.0.0",
17+
"@11ty/eleventy": "3.1.2",
18+
"@11ty/eleventy-navigation": "1.0.4",
1419
"@fec/eleventy-plugin-remark": "4.0.0",
15-
"@tailwindcss/typography": "0.5.2",
20+
"@shikijs/transformers": "3.7.0",
21+
"@tailwindcss/cli": "4.0.17",
22+
"@tailwindcss/postcss": "4.0.17",
23+
"@tailwindcss/typography": "0.5.16",
1624
"@types/hast": "3.0.4",
1725
"@types/mdast": "4.0.4",
1826
"autoprefixer": "10.3.4",
1927
"dedent": "1.5.3",
28+
"hast-util-heading-rank": "3.0.0",
2029
"hastscript": "9.0.1",
2130
"mdast-util-to-hast": "13.2.0",
2231
"postcss": "8.4.23",
2332
"postcss-cli": "8.3.1",
24-
"prismjs": "1.30.0",
2533
"rehype": "13.0.2",
2634
"rehype-autolink-headings": "7.1.0",
2735
"rehype-parse": "9.0.1",
2836
"rehype-slug": "6.0.0",
2937
"remark": "15.0.1",
3038
"remark-directive": "4.0.0",
31-
"tailwindcss": "3.3.2",
39+
"shiki": "3.7.0",
40+
"tailwindcss": "4.0.17",
41+
"tailwindcss-capsize": "4.0.1",
3242
"tailwindcss-opentype": "workspace:*",
3343
"unified": "11.0.5",
44+
"unist-util-remove": "4.0.0",
3445
"unist-util-visit": "5.0.0"
3546
}
3647
}

docs/postcss.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const config = {
2+
plugins: {
3+
'@tailwindcss/postcss': {},
4+
autoprefixer: {},
5+
},
6+
}
7+
8+
export default config

docs/remark/directives.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dedent from 'dedent'
22
import { h } from 'hastscript'
33
import { toHast } from 'mdast-util-to-hast'
4-
import parse from 'rehype-parse'
4+
import rehypeParse from 'rehype-parse'
55
import { unified } from 'unified'
66
import { visit } from 'unist-util-visit'
77

@@ -18,9 +18,10 @@ export function remarkDirectives() {
1818
node.type === 'textDirective'
1919
) {
2020
let data = (node.data ??= {})
21+
/** @type {import('hast').Properties} */
22+
let properties = node.attributes ?? {}
2123
/** @type {import('hast').Element} */
22-
let hast = h(node.name, node.attributes)
23-
let children = []
24+
let hast = h(node.name, properties)
2425

2526
switch (node.name) {
2627
case 'feat': {
@@ -29,20 +30,21 @@ export function remarkDirectives() {
2930
? node.children[0].value.split(',')
3031
: undefined
3132
let features = dedent`
32-
<span aria-hidden="true" class="inline-flex self-center mx-4 h-6 w-px align-middle bg-grey-700 bg-opacity-20"></span>
33-
${tags.map((tag) => markupTagText(tag))}
33+
<span aria-hidden="true" class="inline-flex self-center mx-4 h-6 w-px align-middle bg-grey-900/10 dark:bg-white/15"></span>
34+
${tags?.map((tag) => markupTagText(tag))}
3435
`
3536
.replaceAll('\n', '')
3637
.replaceAll('\t', '')
3738
.replace(',', ' ')
3839

39-
let parsed = unified().use(parse).parse(features)
40-
let html = parsed.children[0]
41-
/** @todo Fix type information here. */
42-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
43-
children = html.children[1].children
40+
let parsed = unified()
41+
.use(rehypeParse, { fragment: true })
42+
.parse(features).children
4443

45-
hast = h(node.name, node.attributes, [children])
44+
hast = h(node.name, properties, parsed)
45+
data.hProperties = {
46+
class: 'not-prose inline',
47+
}
4648
data.hChildren = hast.children
4749
break
4850
}
@@ -52,17 +54,15 @@ export function remarkDirectives() {
5254
<svg class="flex-none h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
5355
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" />
5456
</svg>`
57+
5558
let existing = toHast(node.children[0])
56-
/** @todo Fix type information here. */
57-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
58-
let child = unified().use(parse).parse(icon).children[0]
59-
.children[1].children
59+
let child = unified()
60+
.use(rehypeParse, { fragment: true })
61+
.parse(icon).children
6062

61-
existing.properties.class = '!m-0'
62-
console.log(existing)
6363
hast = h(
6464
'div',
65-
{ class: 'flex gap-4 p-4 bg-grey-100 rounded-lg' },
65+
{ class: 'not-prose flex gap-4 p-4 bg-grey-100 rounded-lg' },
6666
[child, existing],
6767
)
6868
data.hName = hast.tagName
@@ -81,8 +81,11 @@ export function remarkDirectives() {
8181
}
8282
}
8383

84+
/**
85+
* @param {string} tag
86+
*/
8487
function markupTagText(tag) {
85-
return dedent`<span class="align-middle inline-flex items-center px-3 py-1 rounded-full text-sm font-medium leading-4 bg-grey-50 text-grey-600 tracking-tight">
88+
return dedent`<span class="align-middle inline-flex items-center px-3 py-1 rounded-full text-xs font-medium leading-4 bg-grey-50 text-grey-600 tracking-tight dark:bg-grey-900 dark:text-gray-400">
8689
<kbd>${tag}</kbd>
8790
</span>`
8891
}

docs/remark/headings.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { visit } from 'unist-util-visit'
22

33
export function remarkHeadings() {
4-
/** @param {import('@types/mdast').Root} tree */
4+
/** @param {import('mdast').Root} tree */
55
return (tree) => {
66
visit(
77
tree,
88
'heading',
9-
/** @param {import('@types/mdast').Heading} node */ (node) => {
9+
/** @param {import('mdast').Heading} node */ (node) => {
1010
if (node.depth === 1) return
1111

12-
let data = (node.data ??= {})
13-
let properties = (data.hProperties ??= {})
14-
/** @type {string[]} */
15-
let classes = (properties.class ??= [])
16-
17-
classes.push('group flex whitespace-pre-wrap')
12+
node.data ??= {}
13+
node.data.hProperties = {
14+
className: ['group flex whitespace-pre-wrap'],
15+
}
1816
},
1917
)
2018
}

0 commit comments

Comments
 (0)