do11y 0.2.15 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/dist/docs/files.js +1 -1
- package/dist/docs/options.js +2 -1
- package/dist/docs/plugins/markdown.d.ts +2 -1
- package/dist/docs/plugins/markdown.js +3 -1
- package/dist/docs/plugins/options.d.ts +3 -18
- package/dist/docs/plugins/options.js +27 -2
- package/dist/docs/plugins/routes.d.ts +4 -2
- package/dist/docs/plugins/routes.js +36 -15
- package/dist/docs/plugins/sandbox.d.ts +1 -0
- package/dist/docs/plugins/sandbox.js +1 -1
- package/dist/ui/index.js +1 -1
- package/package.json +1 -1
- package/src/types.d.ts +12 -0
package/README.md
CHANGED
|
@@ -13,9 +13,9 @@ Markdown files are treated as single file Vue components with the help of [@mdit
|
|
|
13
13
|
|
|
14
14
|
You can customize the markdown-it instance through the `markdownSetup` option.
|
|
15
15
|
|
|
16
|
-
### Import markdown route files as routes through `do11y:routes`
|
|
16
|
+
### Import markdown route files and pages as routes through `do11y:routes`
|
|
17
17
|
|
|
18
|
-
To include a markdown file as a route it needs to have a `title` and a `slug` (e.g. `/button`) in it's frontmatter.
|
|
18
|
+
To include a markdown file as a route it needs to have a `title` and a `slug` (e.g. `/button`) in it's frontmatter. Or add it inside the `docs/do11y/pages` folder.
|
|
19
19
|
|
|
20
20
|
### [Shiki](https://shiki.style) code highlighting
|
|
21
21
|
|
|
@@ -49,18 +49,12 @@ Document components through meta imports (`Button.vue?meta`) which give a simpli
|
|
|
49
49
|
|
|
50
50
|
Expected as the default export in `docs/do11y/do11y.ts`.
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
interface Options {
|
|
54
|
-
/**
|
|
55
|
-
* The home page.
|
|
56
|
-
*/
|
|
57
|
-
Home: () => Promise<Component>;
|
|
52
|
+
You can specify a layout for each page by adding a `docs/do11y/layout/Page.vue` file with a `<RouterView />` in it.
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
* The layout for each route.
|
|
61
|
-
*/
|
|
62
|
-
Layout?: () => Promise<Component>;
|
|
54
|
+
And you can set the home page by adding `docs/do11y/pages/Home.vue`.
|
|
63
55
|
|
|
56
|
+
```ts
|
|
57
|
+
interface Options {
|
|
64
58
|
/**
|
|
65
59
|
* Additional setup for the app.
|
|
66
60
|
*/
|
|
@@ -134,5 +128,11 @@ interface Options {
|
|
|
134
128
|
* Additional markdown-it setup.
|
|
135
129
|
*/
|
|
136
130
|
markdownSetup?: PluginSimple;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The callback function for rendering code blocks.
|
|
134
|
+
* Will default return the highlighted code generated by Shiki directly.
|
|
135
|
+
*/
|
|
136
|
+
markdownCodeBlock?: (highlightedCode: string, md: MarkdownIt) => string;
|
|
137
137
|
}
|
|
138
138
|
```
|
package/dist/docs/files.js
CHANGED
package/dist/docs/options.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
1
2
|
import { do11y } from "./files.js";
|
|
2
3
|
const resolveOptions = async () => {
|
|
3
|
-
const options = (await import(do11y)).default;
|
|
4
|
+
const options = (await import(join(do11y, "do11y.ts"))).default;
|
|
4
5
|
const themes = options.highlighter?.themes.map(async (theme) => {
|
|
5
6
|
if (typeof theme === "string") {
|
|
6
7
|
return theme;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type MarkdownSfcBlocks } from "@mdit-vue/plugin-sfc";
|
|
2
|
+
import type MarkdownIt from "markdown-it";
|
|
2
3
|
import type { PluginSimple } from "markdown-it";
|
|
3
4
|
import type { Plugin } from "vite";
|
|
4
5
|
export interface MarkdownPluginOptions {
|
|
@@ -10,7 +11,7 @@ export interface MarkdownPluginOptions {
|
|
|
10
11
|
* The callback function for rendering code blocks.
|
|
11
12
|
* Will default return the highlighted code generated by Shiki directly.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
markdownCodeBlock?: (highlightedCode: string, md: MarkdownIt) => string;
|
|
14
15
|
}
|
|
15
16
|
export interface MarkdownItEnv {
|
|
16
17
|
/**
|
|
@@ -14,7 +14,9 @@ export default (options) => {
|
|
|
14
14
|
html: true,
|
|
15
15
|
highlight(code, lang) {
|
|
16
16
|
const highlightedCode = highlightCode(code, lang);
|
|
17
|
-
return options?.
|
|
17
|
+
return options?.markdownCodeBlock
|
|
18
|
+
? options.markdownCodeBlock(highlightedCode, md)
|
|
19
|
+
: highlightedCode;
|
|
18
20
|
},
|
|
19
21
|
});
|
|
20
22
|
md.use(frontmatterPlugin);
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import type { App, Component } from "vue";
|
|
3
|
-
import type { Router
|
|
3
|
+
import type { Router } from "vue-router";
|
|
4
4
|
import type { BundledTheme, ShikiTransformer, StringLiteralUnion, ThemeInput } from "shiki";
|
|
5
5
|
import type { MarkdownPluginOptions } from "./markdown.js";
|
|
6
6
|
export interface Options extends MarkdownPluginOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The home page.
|
|
9
|
-
*/
|
|
10
|
-
Home: () => Promise<Component>;
|
|
11
|
-
/**
|
|
12
|
-
* The layout for each route.
|
|
13
|
-
*/
|
|
14
|
-
Layout?: () => Promise<Component>;
|
|
15
7
|
/**
|
|
16
8
|
* Additional setup for the app.
|
|
17
9
|
*/
|
|
@@ -28,14 +20,6 @@ export interface Options extends MarkdownPluginOptions {
|
|
|
28
20
|
* Custom wrapper component for `.vue.sandbox` imports.
|
|
29
21
|
*/
|
|
30
22
|
SandboxIframe?: () => Promise<Component>;
|
|
31
|
-
/**
|
|
32
|
-
* Custom additional routes.
|
|
33
|
-
*/
|
|
34
|
-
routes?: (RouteRecordRaw & {
|
|
35
|
-
meta: {
|
|
36
|
-
title: string;
|
|
37
|
-
};
|
|
38
|
-
})[];
|
|
39
23
|
/**
|
|
40
24
|
* The code highlighter.
|
|
41
25
|
* - Markdown code blocks
|
|
@@ -93,7 +77,8 @@ export interface ResolvedOptions extends Omit<Options, "highlighter"> {
|
|
|
93
77
|
}
|
|
94
78
|
/**
|
|
95
79
|
* Add ability to access options (`docs/do11y/do11y.ts`)
|
|
96
|
-
* through `do11y:options
|
|
80
|
+
* through `do11y:options`, the home component through `do11y:home`,
|
|
81
|
+
* and the layout component through `do11y:page-layout`.
|
|
97
82
|
*/
|
|
98
83
|
declare const _default: () => Plugin;
|
|
99
84
|
export default _default;
|
|
@@ -1,13 +1,38 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
1
3
|
import { do11y } from "../files.js";
|
|
2
4
|
/**
|
|
3
5
|
* Add ability to access options (`docs/do11y/do11y.ts`)
|
|
4
|
-
* through `do11y:options
|
|
6
|
+
* through `do11y:options`, the home component through `do11y:home`,
|
|
7
|
+
* and the layout component through `do11y:page-layout`.
|
|
5
8
|
*/
|
|
6
9
|
export default () => ({
|
|
7
10
|
name: "do11y:options",
|
|
8
11
|
async resolveId(id, importer) {
|
|
9
12
|
if (id === "do11y:options") {
|
|
10
|
-
return this.resolve(do11y
|
|
13
|
+
return this.resolve(join(do11y, "do11y.js"), importer);
|
|
14
|
+
}
|
|
15
|
+
if (id === "do11y:home") {
|
|
16
|
+
const homeFile = join(do11y, "pages", "Home.vue");
|
|
17
|
+
/* prettier-ignore */
|
|
18
|
+
return existsSync(homeFile)
|
|
19
|
+
? this.resolve(homeFile, importer)
|
|
20
|
+
: `\0do11y:home`;
|
|
21
|
+
}
|
|
22
|
+
if (id === "do11y:page-layout") {
|
|
23
|
+
const pageLayoutFile = join(do11y, "layout", "Page.vue");
|
|
24
|
+
/* prettier-ignore */
|
|
25
|
+
return existsSync(pageLayoutFile)
|
|
26
|
+
? this.resolve(pageLayoutFile, importer)
|
|
27
|
+
: `\0do11y:page-layout`;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
async load(id) {
|
|
31
|
+
if (id === `\0do11y:home` || id === `\0do11y:page-layout`) {
|
|
32
|
+
return {
|
|
33
|
+
code: "export default undefined",
|
|
34
|
+
moduleType: "js",
|
|
35
|
+
};
|
|
11
36
|
}
|
|
12
37
|
},
|
|
13
38
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
/**
|
|
3
|
-
* Adds the ability to import routes
|
|
4
|
-
*
|
|
3
|
+
* Adds the ability to import routes through `do11y:routes`.
|
|
4
|
+
*
|
|
5
|
+
* Routes refer to `*.md` files with a`title` and `slug`
|
|
6
|
+
* or components inside `docs/do11y/pages`.
|
|
5
7
|
*/
|
|
6
8
|
declare const _default: () => Plugin;
|
|
7
9
|
export default _default;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join, parse } from "node:path";
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
3
|
import { globSync } from "tinyglobby";
|
|
3
|
-
import { root } from "../files.js";
|
|
4
|
+
import { root, do11y } from "../files.js";
|
|
4
5
|
import fm from "front-matter";
|
|
6
|
+
import { toParamId } from "./sandbox.js";
|
|
5
7
|
/**
|
|
6
|
-
* Adds the ability to import routes
|
|
7
|
-
*
|
|
8
|
+
* Adds the ability to import routes through `do11y:routes`.
|
|
9
|
+
*
|
|
10
|
+
* Routes refer to `*.md` files with a`title` and `slug`
|
|
11
|
+
* or components inside `docs/do11y/pages`.
|
|
8
12
|
*/
|
|
9
13
|
export default () => {
|
|
10
14
|
const moduleId = "do11y:routes";
|
|
@@ -16,9 +20,13 @@ export default () => {
|
|
|
16
20
|
cwd: root,
|
|
17
21
|
});
|
|
18
22
|
/* prettier-ignore */
|
|
19
|
-
const
|
|
23
|
+
const routes = markdownFiles
|
|
20
24
|
.map((path) => ({ path, frontmatter: fm(readFileSync(path, "utf-8")).attributes }))
|
|
21
25
|
.filter((file) => typeof file.frontmatter.title === "string" && typeof file.frontmatter.slug === "string");
|
|
26
|
+
/* prettier-ignore */
|
|
27
|
+
const pages = existsSync(join(do11y, "pages"))
|
|
28
|
+
? readdirSync(join(do11y, "pages")).filter((page) => page !== "Home.vue" && (page.endsWith(".md") || page.endsWith(".vue")))
|
|
29
|
+
: [];
|
|
22
30
|
return {
|
|
23
31
|
name: "do11y:routes",
|
|
24
32
|
resolveId(id) {
|
|
@@ -28,26 +36,40 @@ export default () => {
|
|
|
28
36
|
},
|
|
29
37
|
load(id) {
|
|
30
38
|
if (id === resolvedModuleId) {
|
|
31
|
-
const stringifiedRoutes =
|
|
39
|
+
const stringifiedRoutes = routes.map((route) => {
|
|
32
40
|
return `{
|
|
33
41
|
path: "${route.frontmatter.slug}",
|
|
34
42
|
meta: ${JSON.stringify(route.frontmatter)},
|
|
35
43
|
component: async () => (await import("${route.path}")).default
|
|
36
44
|
}`.trim();
|
|
37
45
|
});
|
|
38
|
-
const
|
|
39
|
-
title
|
|
40
|
-
slug
|
|
41
|
-
|
|
46
|
+
const stringifiedPages = pages.map((page) => {
|
|
47
|
+
const title = parse(page).name;
|
|
48
|
+
const slug = `/p/${toParamId(title)}`;
|
|
49
|
+
return `{
|
|
50
|
+
path: "${slug}",
|
|
51
|
+
component: async () => (await import("${join(do11y, "pages", page)}")).default,
|
|
52
|
+
|
|
53
|
+
meta: {
|
|
54
|
+
slug: "${slug}",
|
|
55
|
+
title: "${title}",
|
|
56
|
+
},
|
|
57
|
+
}`.trim();
|
|
58
|
+
});
|
|
42
59
|
return `
|
|
60
|
+
import Home from 'do11y:home';
|
|
43
61
|
import options from 'do11y:options';
|
|
44
62
|
|
|
45
63
|
import { RouterView } from 'vue-router';
|
|
46
64
|
|
|
47
|
-
const
|
|
65
|
+
const homeRoute = {
|
|
48
66
|
path: "/",
|
|
49
|
-
|
|
50
|
-
|
|
67
|
+
component: Home,
|
|
68
|
+
|
|
69
|
+
meta: {
|
|
70
|
+
title: "Home",
|
|
71
|
+
slug: "/",
|
|
72
|
+
}
|
|
51
73
|
};
|
|
52
74
|
|
|
53
75
|
const customRoutes = (options.routes ?? []).map(page => ({
|
|
@@ -55,12 +77,11 @@ export default () => {
|
|
|
55
77
|
|
|
56
78
|
meta: {
|
|
57
79
|
slug: page.path,
|
|
58
|
-
|
|
59
80
|
...page.meta,
|
|
60
81
|
}
|
|
61
82
|
}))
|
|
62
83
|
|
|
63
|
-
export default [
|
|
84
|
+
export default [homeRoute, ${stringifiedPages.join(",\n")}, ${stringifiedRoutes.join(",\n")}];
|
|
64
85
|
`;
|
|
65
86
|
}
|
|
66
87
|
},
|
|
@@ -2,7 +2,7 @@ import { join, parse } from "node:path";
|
|
|
2
2
|
import { globSync } from "tinyglobby";
|
|
3
3
|
import { root, ui } from "../files.js";
|
|
4
4
|
import { indexHtml } from "../html/plugin.js";
|
|
5
|
-
const toParamId = (path) => parse(path).name.toLowerCase().replace(".sandbox", "");
|
|
5
|
+
export const toParamId = (path) => parse(path).name.toLowerCase().replace(".sandbox", "").replace(".vue", "");
|
|
6
6
|
/**
|
|
7
7
|
* Creates a seprate sandbox app, and
|
|
8
8
|
* adds access to sandbox components through `do11y:sandbox`.
|
package/dist/ui/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,
|
|
1
|
+
import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,resolveComponent as o,unref as s}from"vue";import c from"do11y:options";import{createRouter as l,createWebHistory as u}from"vue-router";import d from"do11y:routes";import f from"do11y:page-layout";import p from"do11y:css";var m=r({__name:`Page`,setup(e){return i(async()=>{let e=document.createElement(`style`);e.innerHTML=p,document.head.appendChild(e)}),(e,n)=>{let r=o(`RouterView`);return s(f)?(a(),t(s(f),{key:0})):(a(),t(r,{key:1}))}}});(async()=>{let t=l({history:u(`/`),routes:d,scrollBehavior(e,t,n){if(!e.hash)return;let r=document.querySelector(e.hash);if(!r)return;let i=parseFloat(getComputedStyle(r).scrollMarginTop);return{el:e.hash,top:isNaN(i)?n?.top??0:i}}}),n=e(m);await c.setup?.(n,t),n.use(t),n.mount(`#app`)})();
|
package/package.json
CHANGED
package/src/types.d.ts
CHANGED
|
@@ -25,6 +25,18 @@ declare module "do11y:options" {
|
|
|
25
25
|
export default options;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
declare module "do11y:home" {
|
|
29
|
+
import type { Component } from "vue";
|
|
30
|
+
const home: Component | undefined;
|
|
31
|
+
export default home;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module "do11y:page-layout" {
|
|
35
|
+
import type { Component } from "vue";
|
|
36
|
+
const layout: Component | undefined;
|
|
37
|
+
export default layout;
|
|
38
|
+
}
|
|
39
|
+
|
|
28
40
|
declare module "do11y:css" {
|
|
29
41
|
const css: string;
|
|
30
42
|
export default string;
|