Skip to content

Commit 7609812

Browse files
committed
Progress on docs
1 parent c13cfe7 commit 7609812

22 files changed

+600
-462
lines changed

docs-app/app/index.html

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@
1616
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/docs-app.css" />
1717

1818
{{content-for "head-footer"}}
19+
20+
<style>
21+
#kolay__loading {
22+
position: fixed;
23+
inset: 0;
24+
background: #111;
25+
color: white;
26+
font-size: 4rem;
27+
z-index: 10;
28+
font-family: "System UI", "System";
29+
display: flex;
30+
justify-content: center;
31+
align-items: center;
32+
flex-direction: column;
33+
gap: 4rem;
34+
35+
[aria-busy="true"] {
36+
background: #111;
37+
}
38+
}
39+
</style>
1940
</head>
2041

2142
<body>
@@ -24,6 +45,11 @@
2445
<script src="{{rootURL}}assets/vendor.js"></script>
2546
<script src="{{rootURL}}assets/docs-app.js"></script>
2647

48+
<div id="kolay__loading">
49+
Kolay
50+
<article aria-busy="true"></article>
51+
</div>
52+
2753
{{content-for "body-footer"}}
2854
</body>
2955
</html>

docs-app/app/routes/application.ts

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11
import Route from '@ember/routing/route';
22
import { service } from '@ember/service';
33

4+
import rehypeShikiFromHighlighter from '@shikijs/rehype/core';
5+
import { colorScheme, sync } from 'ember-primitives/color-scheme';
6+
import { getHighlighterCore } from 'shiki/core';
7+
import getWasm from 'shiki/wasm';
8+
9+
sync();
10+
411
import type { DocsService, Manifest } from 'kolay';
512

613
export default class ApplicationRoute extends Route {
714
@service('kolay/docs') declare docs: DocsService;
815

916
async model(): Promise<{ manifest: Manifest }> {
17+
const highlighter = await getHighlighterCore({
18+
themes: [import('shiki/themes/github-dark.mjs'), import('shiki/themes/github-light.mjs')],
19+
langs: [
20+
import('shiki/langs/javascript.mjs'),
21+
import('shiki/langs/typescript.mjs'),
22+
import('shiki/langs/bash.mjs'),
23+
import('shiki/langs/css.mjs'),
24+
import('shiki/langs/html.mjs'),
25+
import('shiki/langs/glimmer-js.mjs'),
26+
import('shiki/langs/glimmer-ts.mjs'),
27+
],
28+
langAlias: {
29+
'gjs': 'glimmer-js',
30+
'gts': 'glimmer-ts',
31+
},
32+
loadWasm: getWasm,
33+
});
34+
1035
await this.docs.setup({
11-
apiDocs: await import('kolay/api-docs:virtual'),
12-
manifest: await import('kolay/manifest:virtual'),
36+
apiDocs: import('kolay/api-docs:virtual'),
37+
manifest: import('kolay/manifest:virtual'),
1338
resolve: {
14-
'ember-primitives': await import('ember-primitives'),
15-
kolay: await import('kolay'),
39+
'ember-primitives': import('ember-primitives'),
40+
kolay: import('kolay'),
1641
},
42+
rehypePlugins: [
43+
[
44+
rehypeShikiFromHighlighter,
45+
highlighter,
46+
{
47+
defaultColor: colorScheme.current === 'dark' ? 'dark' : 'light',
48+
themes: {
49+
light: 'github-light',
50+
dark: 'github-dark',
51+
},
52+
},
53+
],
54+
],
1755
});
1856

1957
return { manifest: this.docs.manifest };

docs-app/app/templates/application.gjs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default Route(
2626
</div>
2727
<style>
2828
.application__layout { display: grid; grid-template-columns: max-content 1fr; gap: 2rem; }
29+
header { filter: drop-shadow(0 10px 0.75rem #000000); }
2930
</style>
3031
</template>
3132
);

docs-app/app/templates/nav.gts

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Component from '@glimmer/component';
22
import { service } from '@ember/service';
33

4+
import { pascalCase } from 'change-case';
5+
46
import type { TOC } from '@ember/component/template-only';
57
import type RouterService from '@ember/routing/router-service';
68
import type { Collection, DocsService, Page } from 'kolay';
@@ -9,17 +11,34 @@ export class Nav extends Component {
911
@service('kolay/docs') declare docs: DocsService;
1012

1113
<template>
12-
<nav>
14+
<nav id="side-nav">
1315
<Pages @item={{this.docs.tree}} />
1416
</nav>
15-
<style>nav ul { padding-left: 0.5rem; list-style: none; line-height: 1.75rem; }</style>
17+
<style>
18+
nav#side-nav { min-width: 150px; ul { padding-left: 0.5rem; list-style: none; line-height:
19+
1.75rem; } }
20+
</style>
1621
</template>
1722
}
1823

1924
function isCollection(x: Page | Collection): x is Collection {
2025
return 'pages' in x;
2126
}
2227

28+
function nameFor(x: Page) {
29+
// We defined componentName via json file
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31+
if ('componentName' in x) {
32+
return `${x.componentName}`;
33+
}
34+
35+
if (x.path.includes('/components/')) {
36+
return `<${pascalCase(x.name)} />`;
37+
}
38+
39+
return x.name;
40+
}
41+
2342
const Pages: TOC<{ Args: { item: Page | Collection } }> = <template>
2443
<ul>
2544
{{#if (isCollection @item)}}
@@ -33,7 +52,7 @@ const Pages: TOC<{ Args: { item: Page | Collection } }> = <template>
3352
</li>
3453
{{/each}}
3554
{{else}}
36-
<a href={{@item.path}}>{{@item.name}}</a>
55+
<a href={{@item.path}}>{{nameFor @item}}</a>
3756
{{/if}}
3857
</ul>
3958
</template>;

docs-app/app/templates/page.gjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { service } from 'ember-primitives/helpers';
22
import Route from 'ember-route-template';
3-
import { highlight } from 'kolay';
3+
4+
function removeLoader() {
5+
document.querySelector('#kolay__loading')?.remove();
6+
}
47

58
export default Route(
69
<template>
710
{{#let (service "kolay/docs") as |docs|}}
8-
<div
9-
data-prose
10-
class="prose p-4"
11-
{{(if docs.selected.prose (modifier highlight docs.selected.prose))}}
12-
>
11+
<div data-prose class="prose p-4">
1312
{{#if docs.selected.hasError}}
1413
<div style="border: 1px solid red; padding: 1rem;">
1514
{{docs.selected.error}}
@@ -18,6 +17,7 @@ export default Route(
1817

1918
{{#if docs.selected.prose}}
2019
<docs.selected.prose />
20+
{{(removeLoader)}}
2121
{{/if}}
2222
</div>
2323
{{/let}}

docs-app/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"stylelint-prettier": "^5.0.0",
8585
"tracked-built-ins": "^3.3.0",
8686
"typescript": "^5.3.3",
87-
"webpack": "^5.89.0"
87+
"webpack": "^5.90.3"
8888
},
8989
"engines": {
9090
"node": ">= 18"
@@ -96,14 +96,17 @@
9696
"extends": "../package.json"
9797
},
9898
"dependencies": {
99+
"@shikijs/rehype": "^1.1.7",
99100
"@universal-ember/kolay-ui": "workspace:^",
100101
"@universal-ember/test-support": "^0.0.0",
102+
"change-case": "^5.4.3",
101103
"ember-async-data": "^1.0.3",
102104
"ember-cached-decorator-polyfill": "^1.0.2",
103-
"ember-repl": "3.0.0",
105+
"ember-repl": "^4.1.1",
104106
"ember-route-template": "^1.0.3",
105107
"kolay": "workspace:^",
106-
"reactiveweb": "^1.2.1"
108+
"reactiveweb": "^1.2.1",
109+
"shiki": "^1.1.7"
107110
},
108111
"dependenciesMeta": {
109112
"kolay": {

docs-app/public/docs/usage/setup.md

+34-12
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,67 @@
1818

1919
<hr>
2020

21+
## Install[^type-module]
22+
23+
```bash
24+
pnpm add kolay @universal-ember/kolay-ui
25+
```
26+
27+
[^type-module]: `@universal-ember/kolay-ui` is only needed because due to a temporary technical problem. Once the ember ecosystem has broader `package.json#type=module` support for its own ember using libraries, `@universal-ember/kolay-ui` can be removed and there will only be `kolay`. Note that `package.json#type=module` support is already working and has worked for a good number of years for non-Ember libraries.
28+
2129
## Setup
2230

23-
There are two areas of configuration needed: buildtime, and runtime.
31+
There are two areas of configuration needed: buildtime, and runtime[^runtime-optional].
32+
33+
[^runtime-optional]: The runtime components are optional and if you don't import them, they will not be included in your app. However, since links generated from markdown use vanilla `<a>` tags, you'll probably want at least `@properLinks` from `ember-primitives`.
2434

2535
### Build: Embroider + Webpack
2636

2737
import `kolay/webpack`
2838

2939
```js
30-
const { createManifest, apiDocs } = await import("kolay/webpack");
40+
const { kolay } = await import("kolay/webpack");
3141

3242
return require("@embroider/compat").compatBuild(app, Webpack, {
3343
/* ... */
3444
packagerOptions: {
3545
webpackConfig: {
3646
devtool: "source-map",
37-
plugins: [createManifest({ src: "public/docs" }), apiDocs({ package: "kolay" })],
47+
plugins: [
48+
kolay({
49+
src: "public/docs",
50+
// Generate API docs from JSDoc
51+
packages: ["kolay"],
52+
}),
53+
],
3854
},
3955
},
4056
});
4157
```
4258

43-
You can create docs for multiple libraries by invoking these plugins more than once:
59+
You can create docs for multiple libraries at once:
4460

4561
```js
4662
devtool: 'source-map',
4763
plugins: [
48-
createManifest({ src: 'public/docs', name: 'own-manifest.json' }),
49-
apiDocs({ package: 'kolay' }),
50-
createManifest({ src: '../../my-library', name: 'my-library-manifest.json' }),
51-
apiDocs({ package: 'my-library' }),
64+
kolay({
65+
src: 'public/docs',
66+
groups: [
67+
{
68+
name: 'Runtime',
69+
src: '../ui/docs',
70+
},
71+
],
72+
// Generate API docs from JSDoc
73+
// NOTE: these must all be declared in your projects package.json
74+
packages: ['kolay', 'ember-primitives', 'ember-resources'],
75+
}),
5276
],
5377
```
5478

55-
See related for
79+
This is useful for monorepos where they may be scaling to large teams and many packages could end up being added quickly. In a traditionally compiled app, this may cause build times to slow down over time. Since many docs' sites are deployed continuously, that is wasted time and money spent on building things that may not be looked at all that often (we all wish folks looked at docs more!).
5680

57-
- [createManifest(...)](/plugins/create-manifest.md)
58-
- [apiDocs(...)](/plugins/api-docs.md)
59-
- [All Build Plugins](/plugins/index.md)
81+
By distributing the rendering of pages to the browesr, we only pay for "build" when somenoe views the page.
6082

6183
### Runtime: Routing
6284

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"concurrently": "^8.2.2",
105105
"ember-modifier": "^4.1.0",
106106
"ember-primitives": "^0.11.3",
107-
"ember-repl": "3.0.0",
107+
"ember-repl": "^4.1.1",
108108
"ember-resources": "^7.0.0",
109109
"ember-source": "~5.7.0",
110110
"eslint": "^8.56.0",
@@ -118,7 +118,7 @@
118118
"typescript": "^5.3.3",
119119
"vite": "^5.1.3",
120120
"vitest": "^1.2.2",
121-
"webpack": "^5.89.0"
121+
"webpack": "^5.90.3"
122122
},
123123
"engines": {
124124
"node": ">= 18"
@@ -167,7 +167,7 @@
167167
"overrides": {
168168
"@ember/test-waiters": "^3.1.0",
169169
"webpack": "^5.90.3",
170-
"ember-repl": "^3.0.0"
170+
"ember-repl": "^4.1.1"
171171
}
172172
},
173173
"volta": {
@@ -182,7 +182,7 @@
182182
"@universal-ember/kolay-ui": "workspace:^",
183183
"ember-modifier": "^4.1.0",
184184
"ember-primitives": "^0.11.3",
185-
"ember-repl": "3.0.0-beta.8",
185+
"ember-repl": "^4.1.1",
186186
"ember-resources": "^7.0.0",
187187
"ember-source": "~5.5.0",
188188
"reactiveweb": "^1.2.1",

0 commit comments

Comments
 (0)