Skip to content

Commit b321607

Browse files
authored
Split into monorepo & upgrade 11ty to ESM (#96)
Upgrades 11ty docs to ESM. Split into monorepo because TS is configured to build the plugin into CJS which conflicts with the `module` type used in the docs package.
1 parent b6a7280 commit b321607

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+8480
-16475
lines changed

.eslintrc.cjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ const config = {
88
env: {
99
node: true,
1010
},
11-
ignorePatterns: ['dist', 'docs' /* , '!.eleventy.js' */],
11+
ignorePatterns: ['dist'],
1212
rules: {
1313
'@typescript-eslint/ban-types': 'off',
1414
'@typescript-eslint/lines-between-class-members': 'off',
1515
'@typescript-eslint/padding-line-between-statements': 'off',
1616

17+
/**
18+
* Currently conflicting with 'yoda' and 'unicorn/explicit-length-check'.
19+
*/
20+
'etc/prefer-less-than': 'off',
21+
1722
'n/file-extension-in-import': ['error', 'always'],
23+
24+
'no-multi-assign': 'off',
1825
},
1926
overrides: [
2027
{
@@ -34,6 +41,12 @@ const config = {
3441
'prefer-let/prefer-let': 'off',
3542
},
3643
},
44+
{
45+
files: ['docs/**/*.js'],
46+
rules: {
47+
'import/no-extraneous-dependencies': 'off',
48+
},
49+
},
3750
],
3851
}
3952

.github/workflows/main.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10+
# https://github.com/actions/checkout
1011
- name: Checkout repo
11-
uses: actions/checkout@v3
12+
uses: actions/checkout@v4
13+
14+
# https://github.com/pnpm/action-setup
15+
- uses: pnpm/action-setup@v2
16+
with:
17+
version: 10
1218

1319
- name: Setup Node.js 18.x
1420
uses: actions/setup-node@v3.1.1
1521
with:
1622
node-version: 18.x
17-
cache: npm
23+
cache: pnpm
1824

1925
- name: Install dependencies
20-
run: npm ci
26+
run: pnpm install --frozen-lockfile
2127

2228
- name: Build
2329
run: npm run build

.github/workflows/release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ jobs:
1616
with:
1717
fetch-depth: 0
1818

19+
# https://github.com/pnpm/action-setup
20+
- uses: pnpm/action-setup@v2
21+
with:
22+
version: 10
23+
1924
- name: Setup Node.js 18.x
2025
uses: actions/setup-node@v3.1.1
2126
with:
2227
node-version: 18.x
23-
cache: npm
28+
cache: pnpm
2429

2530
- name: Install dependencies
26-
run: npm ci
31+
run: pnpm install --frozen-lockfile
2732

2833
# https://github.com/changesets/action
2934
- name: Create release PR or publish to npm

.husky/pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# Disable hooks in CI.
4+
[ -n "$CI" ] && exit 0
5+
6+
npx lint-staged

docs/.eleventy.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

docs/eleventy.config.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
2+
3+
import eleventyNavigationPlugin from '@11ty/eleventy-navigation'
4+
import eleventyRemark from '@fec/eleventy-plugin-remark'
5+
import dedent from 'dedent'
6+
import { rehype } from 'rehype'
7+
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
8+
import rehypeSlug from 'rehype-slug'
9+
import { remark } from 'remark'
10+
import remarkDirective from 'remark-directive'
11+
12+
import { remarkDirectives } from './remark/directives.js'
13+
import { remarkHeadings } from './remark/headings.js'
14+
import { remarkSample } from './remark/sample.js'
15+
16+
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
17+
export default async function config(eleventyConfig) {
18+
eleventyConfig.addPassthroughCopy({
19+
'src/assets/fonts': './assets/fonts',
20+
})
21+
eleventyConfig.addPassthroughCopy({
22+
'src/assets/images': './assets/images',
23+
})
24+
eleventyConfig.addPassthroughCopy({ 'src/public': '.' })
25+
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+
52+
eleventyConfig.addPlugin(eleventyNavigationPlugin)
53+
eleventyConfig.addPlugin(eleventyRemark, {
54+
plugins: [
55+
remarkHeadings,
56+
remarkDirective,
57+
remarkDirectives,
58+
remarkSample,
59+
// Require('./remark/prose'),
60+
],
61+
})
62+
63+
eleventyConfig.addTransform(
64+
'rehype',
65+
/** @param {string} content */ async (content, outputPath) => {
66+
let newContent = content
67+
68+
if (outputPath?.endsWith('.html')) {
69+
let result = await rehype()
70+
.use(rehypeSlug)
71+
.use(rehypeAutolinkHeadings, {
72+
test: (element, index, parent) => parent.tagName !== 'nav',
73+
properties: {
74+
class:
75+
'absolute ml-[-0.75em] md:ml-[-1em] pr-[0.5em] !no-underline !text-grey-400 opacity-0 group-hover:opacity-100',
76+
},
77+
content: {
78+
type: 'text',
79+
value: '¶',
80+
},
81+
})
82+
.process(content)
83+
84+
newContent = result.toString()
85+
}
86+
87+
return newContent
88+
},
89+
)
90+
91+
return {
92+
dir: {
93+
input: 'src',
94+
data: 'data',
95+
includes: 'includes',
96+
layouts: 'layouts',
97+
output: 'dist',
98+
},
99+
// PathPrefix:
100+
// process.env.NODE_ENV === 'production'
101+
// ? '/tailwindcss-opentype/'
102+
// : '',
103+
}
104+
}

docs/package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "docs",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build": "eleventy --config=eleventy.config.js",
8+
"dev": "TAILWIND_MODE=watch eleventy --config=eleventy.config.js --serve"
9+
},
10+
"devDependencies": {
11+
"@11ty/eleventy": "3.0.0",
12+
"@11ty/eleventy-navigation": "0.3.5",
13+
"@11ty/eleventy-plugin-syntaxhighlight": "5.0.0",
14+
"@fec/eleventy-plugin-remark": "4.0.0",
15+
"@tailwindcss/typography": "0.5.2",
16+
"@types/hast": "3.0.4",
17+
"@types/mdast": "4.0.4",
18+
"autoprefixer": "10.3.4",
19+
"dedent": "1.5.3",
20+
"hastscript": "9.0.1",
21+
"mdast-util-to-hast": "13.2.0",
22+
"postcss": "8.4.23",
23+
"postcss-cli": "8.3.1",
24+
"prismjs": "1.30.0",
25+
"rehype": "13.0.2",
26+
"rehype-autolink-headings": "7.1.0",
27+
"rehype-parse": "9.0.1",
28+
"rehype-slug": "6.0.0",
29+
"remark": "15.0.1",
30+
"remark-directive": "4.0.0",
31+
"tailwindcss": "3.3.2",
32+
"tailwindcss-opentype": "workspace:*",
33+
"unified": "11.0.5",
34+
"unist-util-visit": "5.0.0"
35+
}
36+
}

0 commit comments

Comments
 (0)