@ztl-uwu/nuxt-content 2.13.5
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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/module.d.mts +1176 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +696 -0
- package/dist/runtime/app.vue +3 -0
- package/dist/runtime/app.vue.d.ts +2 -0
- package/dist/runtime/components/ContentDoc.vue +108 -0
- package/dist/runtime/components/ContentDoc.vue.d.ts +118 -0
- package/dist/runtime/components/ContentList.vue +59 -0
- package/dist/runtime/components/ContentList.vue.d.ts +59 -0
- package/dist/runtime/components/ContentNavigation.vue +61 -0
- package/dist/runtime/components/ContentNavigation.vue.d.ts +35 -0
- package/dist/runtime/components/ContentQuery.vue +212 -0
- package/dist/runtime/components/ContentQuery.vue.d.ts +0 -0
- package/dist/runtime/components/ContentRenderer.vue +78 -0
- package/dist/runtime/components/ContentRenderer.vue.d.ts +56 -0
- package/dist/runtime/components/ContentRendererMarkdown.vue +69 -0
- package/dist/runtime/components/ContentRendererMarkdown.vue.d.ts +73 -0
- package/dist/runtime/components/ContentSlot.vue +25 -0
- package/dist/runtime/components/ContentSlot.vue.d.ts +37 -0
- package/dist/runtime/components/DocumentDrivenEmpty.vue +18 -0
- package/dist/runtime/components/DocumentDrivenEmpty.vue.d.ts +17 -0
- package/dist/runtime/components/DocumentDrivenNotFound.vue +9 -0
- package/dist/runtime/components/DocumentDrivenNotFound.vue.d.ts +5 -0
- package/dist/runtime/components/Markdown.vue +29 -0
- package/dist/runtime/components/Markdown.vue.d.ts +31 -0
- package/dist/runtime/components/Prose/ProseCode.vue +32 -0
- package/dist/runtime/components/Prose/ProseCode.vue.d.ts +110 -0
- package/dist/runtime/components/Prose/ProseCodeInline.vue +3 -0
- package/dist/runtime/components/Prose/ProseCodeInline.vue.d.ts +14 -0
- package/dist/runtime/components/Prose/ProsePre.vue +42 -0
- package/dist/runtime/components/Prose/ProsePre.vue.d.ts +146 -0
- package/dist/runtime/composables/client-db.d.ts +14 -0
- package/dist/runtime/composables/client-db.js +105 -0
- package/dist/runtime/composables/content.d.ts +19 -0
- package/dist/runtime/composables/content.js +41 -0
- package/dist/runtime/composables/head.d.ts +4 -0
- package/dist/runtime/composables/head.js +94 -0
- package/dist/runtime/composables/helpers.d.ts +7 -0
- package/dist/runtime/composables/helpers.js +66 -0
- package/dist/runtime/composables/navigation.d.ts +2 -0
- package/dist/runtime/composables/navigation.js +34 -0
- package/dist/runtime/composables/preview.d.ts +5 -0
- package/dist/runtime/composables/preview.js +41 -0
- package/dist/runtime/composables/query.d.ts +10 -0
- package/dist/runtime/composables/query.js +64 -0
- package/dist/runtime/composables/search.d.ts +130 -0
- package/dist/runtime/composables/search.js +59 -0
- package/dist/runtime/composables/useUnwrap.d.ts +5 -0
- package/dist/runtime/composables/useUnwrap.js +5 -0
- package/dist/runtime/composables/utils.d.ts +6 -0
- package/dist/runtime/composables/utils.js +36 -0
- package/dist/runtime/composables/web-socket.d.ts +3 -0
- package/dist/runtime/composables/web-socket.js +65 -0
- package/dist/runtime/legacy/composables/client-db.d.ts +12 -0
- package/dist/runtime/legacy/composables/client-db.js +105 -0
- package/dist/runtime/legacy/composables/navigation.d.ts +2 -0
- package/dist/runtime/legacy/composables/navigation.js +34 -0
- package/dist/runtime/legacy/composables/query.d.ts +10 -0
- package/dist/runtime/legacy/composables/query.js +61 -0
- package/dist/runtime/legacy/plugins/documentDriven.d.ts +2 -0
- package/dist/runtime/legacy/plugins/documentDriven.js +231 -0
- package/dist/runtime/legacy/server.d.ts +3 -0
- package/dist/runtime/legacy/server.js +3 -0
- package/dist/runtime/legacy/types.d.ts +5 -0
- package/dist/runtime/pages/document-driven.vue +27 -0
- package/dist/runtime/pages/document-driven.vue.d.ts +2 -0
- package/dist/runtime/plugins/documentDriven.d.ts +2 -0
- package/dist/runtime/plugins/documentDriven.js +222 -0
- package/dist/runtime/plugins/ws.d.ts +2 -0
- package/dist/runtime/plugins/ws.js +7 -0
- package/dist/runtime/query/match/index.d.ts +6 -0
- package/dist/runtime/query/match/index.js +123 -0
- package/dist/runtime/query/match/pipeline-legacy.d.ts +2 -0
- package/dist/runtime/query/match/pipeline-legacy.js +22 -0
- package/dist/runtime/query/match/pipeline.d.ts +2 -0
- package/dist/runtime/query/match/pipeline.js +104 -0
- package/dist/runtime/query/match/utils.d.ts +35 -0
- package/dist/runtime/query/match/utils.js +65 -0
- package/dist/runtime/query/query.d.ts +12 -0
- package/dist/runtime/query/query.js +61 -0
- package/dist/runtime/server/api/cache.d.ts +7 -0
- package/dist/runtime/server/api/cache.js +18 -0
- package/dist/runtime/server/api/navigation-qid-params.d.ts +1 -0
- package/dist/runtime/server/api/navigation-qid-params.js +1 -0
- package/dist/runtime/server/api/navigation-qid.d.ts +1 -0
- package/dist/runtime/server/api/navigation-qid.js +1 -0
- package/dist/runtime/server/api/navigation.d.ts +2 -0
- package/dist/runtime/server/api/navigation.js +42 -0
- package/dist/runtime/server/api/query-qid-params.d.ts +1 -0
- package/dist/runtime/server/api/query-qid-params.js +1 -0
- package/dist/runtime/server/api/query-qid.d.ts +1 -0
- package/dist/runtime/server/api/query-qid.js +1 -0
- package/dist/runtime/server/api/query.d.ts +2 -0
- package/dist/runtime/server/api/query.js +32 -0
- package/dist/runtime/server/api/search.d.ts +8 -0
- package/dist/runtime/server/api/search.js +16 -0
- package/dist/runtime/server/content-index.d.ts +4 -0
- package/dist/runtime/server/content-index.js +37 -0
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +1 -0
- package/dist/runtime/server/navigation.d.ts +5 -0
- package/dist/runtime/server/navigation.js +96 -0
- package/dist/runtime/server/plugins/refresh-cache.d.ts +2 -0
- package/dist/runtime/server/plugins/refresh-cache.js +15 -0
- package/dist/runtime/server/preview.d.ts +5 -0
- package/dist/runtime/server/preview.js +9 -0
- package/dist/runtime/server/search.d.ts +14 -0
- package/dist/runtime/server/search.js +70 -0
- package/dist/runtime/server/storage.d.ts +35 -0
- package/dist/runtime/server/storage.js +238 -0
- package/dist/runtime/transformers/component-resolver.d.ts +2 -0
- package/dist/runtime/transformers/component-resolver.js +44 -0
- package/dist/runtime/transformers/csv/create-tokenizer.d.ts +39 -0
- package/dist/runtime/transformers/csv/create-tokenizer.js +307 -0
- package/dist/runtime/transformers/csv/from-csv.d.ts +13 -0
- package/dist/runtime/transformers/csv/from-csv.js +203 -0
- package/dist/runtime/transformers/csv/index.d.ts +2 -0
- package/dist/runtime/transformers/csv/index.js +50 -0
- package/dist/runtime/transformers/csv/parser.d.ts +24 -0
- package/dist/runtime/transformers/csv/parser.js +154 -0
- package/dist/runtime/transformers/index.d.ts +7 -0
- package/dist/runtime/transformers/index.js +50 -0
- package/dist/runtime/transformers/json.d.ts +2 -0
- package/dist/runtime/transformers/json.js +29 -0
- package/dist/runtime/transformers/markdown.d.ts +2 -0
- package/dist/runtime/transformers/markdown.js +88 -0
- package/dist/runtime/transformers/path-meta.d.ts +27 -0
- package/dist/runtime/transformers/path-meta.js +59 -0
- package/dist/runtime/transformers/utils.d.ts +3 -0
- package/dist/runtime/transformers/utils.js +12 -0
- package/dist/runtime/transformers/yaml.d.ts +2 -0
- package/dist/runtime/transformers/yaml.js +21 -0
- package/dist/runtime/utils/config.d.ts +4 -0
- package/dist/runtime/utils/config.js +7 -0
- package/dist/runtime/utils/html-tags.d.ts +2 -0
- package/dist/runtime/utils/html-tags.js +119 -0
- package/dist/runtime/utils/json.d.ts +10 -0
- package/dist/runtime/utils/json.js +20 -0
- package/dist/runtime/utils/query.d.ts +5 -0
- package/dist/runtime/utils/query.js +77 -0
- package/dist/runtime/virtual/transformers.d.ts +2 -0
- package/dist/types.d.mts +9 -0
- package/dist/web-types.json +572 -0
- package/package.json +111 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { markdownLineEnding, markdownSpace } from "micromark-util-character";
|
|
2
|
+
import { createTokenizer } from "./create-tokenizer.js";
|
|
3
|
+
function initializeDocument(effects) {
|
|
4
|
+
const self = this;
|
|
5
|
+
const delimiter = (this.parser.delimiter || ",").charCodeAt(0);
|
|
6
|
+
return enterRow;
|
|
7
|
+
function enterRow(code) {
|
|
8
|
+
return effects.attempt(
|
|
9
|
+
{ tokenize: attemptLastLine },
|
|
10
|
+
(code2) => {
|
|
11
|
+
effects.consume(code2);
|
|
12
|
+
return enterRow;
|
|
13
|
+
},
|
|
14
|
+
(code2) => {
|
|
15
|
+
effects.enter("row");
|
|
16
|
+
return enterColumn(code2);
|
|
17
|
+
}
|
|
18
|
+
)(code);
|
|
19
|
+
}
|
|
20
|
+
function enterColumn(code) {
|
|
21
|
+
effects.enter("column");
|
|
22
|
+
return content(code);
|
|
23
|
+
}
|
|
24
|
+
function content(code) {
|
|
25
|
+
if (code === null) {
|
|
26
|
+
effects.exit("column");
|
|
27
|
+
effects.exit("row");
|
|
28
|
+
effects.consume(code);
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
if (code === 34) {
|
|
32
|
+
return quotedData(code);
|
|
33
|
+
}
|
|
34
|
+
if (code === delimiter) {
|
|
35
|
+
if (self.previous === delimiter || markdownLineEnding(self.previous) || self.previous === null) {
|
|
36
|
+
effects.enter("data");
|
|
37
|
+
effects.exit("data");
|
|
38
|
+
}
|
|
39
|
+
effects.exit("column");
|
|
40
|
+
effects.enter("columnSeparator");
|
|
41
|
+
effects.consume(code);
|
|
42
|
+
effects.exit("columnSeparator");
|
|
43
|
+
effects.enter("column");
|
|
44
|
+
return content;
|
|
45
|
+
}
|
|
46
|
+
if (markdownLineEnding(code)) {
|
|
47
|
+
effects.exit("column");
|
|
48
|
+
effects.enter("newline");
|
|
49
|
+
effects.consume(code);
|
|
50
|
+
effects.exit("newline");
|
|
51
|
+
effects.exit("row");
|
|
52
|
+
return enterRow;
|
|
53
|
+
}
|
|
54
|
+
return data(code);
|
|
55
|
+
}
|
|
56
|
+
function data(code) {
|
|
57
|
+
effects.enter("data");
|
|
58
|
+
return dataChunk(code);
|
|
59
|
+
}
|
|
60
|
+
function dataChunk(code) {
|
|
61
|
+
if (code === null || markdownLineEnding(code) || code === delimiter) {
|
|
62
|
+
effects.exit("data");
|
|
63
|
+
return content(code);
|
|
64
|
+
}
|
|
65
|
+
if (code === 92) {
|
|
66
|
+
return escapeCharacter(code);
|
|
67
|
+
}
|
|
68
|
+
effects.consume(code);
|
|
69
|
+
return dataChunk;
|
|
70
|
+
}
|
|
71
|
+
function escapeCharacter(code) {
|
|
72
|
+
effects.consume(code);
|
|
73
|
+
return function(code2) {
|
|
74
|
+
effects.consume(code2);
|
|
75
|
+
return content;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function quotedData(code) {
|
|
79
|
+
effects.enter("quotedData");
|
|
80
|
+
effects.enter("quotedDataChunk");
|
|
81
|
+
effects.consume(code);
|
|
82
|
+
return quotedDataChunk;
|
|
83
|
+
}
|
|
84
|
+
function quotedDataChunk(code) {
|
|
85
|
+
if (code === 92) {
|
|
86
|
+
return escapeCharacter(code);
|
|
87
|
+
}
|
|
88
|
+
if (code === 34) {
|
|
89
|
+
return effects.attempt(
|
|
90
|
+
{ tokenize: attemptDoubleQuote },
|
|
91
|
+
(code2) => {
|
|
92
|
+
effects.exit("quotedDataChunk");
|
|
93
|
+
effects.enter("quotedDataChunk");
|
|
94
|
+
return quotedDataChunk(code2);
|
|
95
|
+
},
|
|
96
|
+
(code2) => {
|
|
97
|
+
effects.consume(code2);
|
|
98
|
+
effects.exit("quotedDataChunk");
|
|
99
|
+
effects.exit("quotedData");
|
|
100
|
+
return content;
|
|
101
|
+
}
|
|
102
|
+
)(code);
|
|
103
|
+
}
|
|
104
|
+
effects.consume(code);
|
|
105
|
+
return quotedDataChunk;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function attemptDoubleQuote(effects, ok, nok) {
|
|
109
|
+
return startSequence;
|
|
110
|
+
function startSequence(code) {
|
|
111
|
+
if (code !== 34) {
|
|
112
|
+
return nok(code);
|
|
113
|
+
}
|
|
114
|
+
effects.enter("quoteFence");
|
|
115
|
+
effects.consume(code);
|
|
116
|
+
return sequence;
|
|
117
|
+
}
|
|
118
|
+
function sequence(code) {
|
|
119
|
+
if (code !== 34) {
|
|
120
|
+
return nok(code);
|
|
121
|
+
}
|
|
122
|
+
effects.consume(code);
|
|
123
|
+
effects.exit("quoteFence");
|
|
124
|
+
return (code2) => ok(code2);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function attemptLastLine(effects, ok, nok) {
|
|
128
|
+
return enterLine;
|
|
129
|
+
function enterLine(code) {
|
|
130
|
+
if (!markdownSpace(code) && code !== null) {
|
|
131
|
+
return nok(code);
|
|
132
|
+
}
|
|
133
|
+
effects.enter("emptyLine");
|
|
134
|
+
return continueLine(code);
|
|
135
|
+
}
|
|
136
|
+
function continueLine(code) {
|
|
137
|
+
if (markdownSpace(code)) {
|
|
138
|
+
effects.consume(code);
|
|
139
|
+
return continueLine;
|
|
140
|
+
}
|
|
141
|
+
if (code === null) {
|
|
142
|
+
effects.exit("emptyLine");
|
|
143
|
+
return ok(code);
|
|
144
|
+
}
|
|
145
|
+
return nok(code);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export const parse = (options) => {
|
|
149
|
+
return createTokenizer(
|
|
150
|
+
{ ...options },
|
|
151
|
+
{ tokenize: initializeDocument },
|
|
152
|
+
void 0
|
|
153
|
+
);
|
|
154
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StorageValue } from 'unstorage';
|
|
2
|
+
import type { TransformContentOptions } from '@nuxt/content';
|
|
3
|
+
/**
|
|
4
|
+
* Parse content file using registered plugins
|
|
5
|
+
*/
|
|
6
|
+
export declare function transformContent(id: string, content: StorageValue, options?: TransformContentOptions): Promise<any>;
|
|
7
|
+
export { defineTransformer } from './utils';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { extname } from "pathe";
|
|
2
|
+
import { camelCase } from "scule";
|
|
3
|
+
import csv from "./csv/index.js";
|
|
4
|
+
import markdown from "./markdown.js";
|
|
5
|
+
import yaml from "./yaml.js";
|
|
6
|
+
import pathMeta from "./path-meta.js";
|
|
7
|
+
import json from "./json.js";
|
|
8
|
+
const TRANSFORMERS = [
|
|
9
|
+
csv,
|
|
10
|
+
markdown,
|
|
11
|
+
json,
|
|
12
|
+
yaml,
|
|
13
|
+
pathMeta
|
|
14
|
+
];
|
|
15
|
+
function getParser(ext, additionalTransformers = []) {
|
|
16
|
+
let parser = additionalTransformers.find((p) => ext.match(new RegExp(p.extensions.join("|"), "i")) && p.parse);
|
|
17
|
+
if (!parser) {
|
|
18
|
+
parser = TRANSFORMERS.find((p) => ext.match(new RegExp(p.extensions.join("|"), "i")) && p.parse);
|
|
19
|
+
}
|
|
20
|
+
return parser;
|
|
21
|
+
}
|
|
22
|
+
function getTransformers(ext, additionalTransformers = []) {
|
|
23
|
+
return [
|
|
24
|
+
...additionalTransformers.filter((p) => ext.match(new RegExp(p.extensions.join("|"), "i")) && p.transform),
|
|
25
|
+
...TRANSFORMERS.filter((p) => ext.match(new RegExp(p.extensions.join("|"), "i")) && p.transform)
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
export async function transformContent(id, content, options = {}) {
|
|
29
|
+
const { transformers = [] } = options;
|
|
30
|
+
const file = { _id: id, body: content };
|
|
31
|
+
const ext = extname(id);
|
|
32
|
+
const parser = getParser(ext, transformers);
|
|
33
|
+
if (!parser) {
|
|
34
|
+
console.warn(`${ext} files are not supported, "${id}" falling back to raw content`);
|
|
35
|
+
return file;
|
|
36
|
+
}
|
|
37
|
+
const parserOptions = options[camelCase(parser.name)] || {};
|
|
38
|
+
const parsed = await parser.parse(file._id, file.body, parserOptions);
|
|
39
|
+
const matchedTransformers = getTransformers(ext, transformers);
|
|
40
|
+
const result = await matchedTransformers.reduce(async (prev, cur) => {
|
|
41
|
+
const next = await prev || parsed;
|
|
42
|
+
const transformOptions = options[camelCase(cur.name)];
|
|
43
|
+
if (transformOptions === false) {
|
|
44
|
+
return next;
|
|
45
|
+
}
|
|
46
|
+
return cur.transform(next, transformOptions || {});
|
|
47
|
+
}, Promise.resolve(parsed));
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
export { defineTransformer } from "./utils.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { destr } from "destr";
|
|
2
|
+
import { defineTransformer } from "./utils.js";
|
|
3
|
+
export default defineTransformer({
|
|
4
|
+
name: "Json",
|
|
5
|
+
extensions: [".json", ".json5"],
|
|
6
|
+
parse: async (_id, content) => {
|
|
7
|
+
let parsed;
|
|
8
|
+
if (typeof content === "string") {
|
|
9
|
+
if (_id.endsWith("json5")) {
|
|
10
|
+
parsed = (await import("json5").then((m) => m.default || m)).parse(content);
|
|
11
|
+
} else if (_id.endsWith("json")) {
|
|
12
|
+
parsed = destr(content);
|
|
13
|
+
}
|
|
14
|
+
} else {
|
|
15
|
+
parsed = content;
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(parsed)) {
|
|
18
|
+
console.warn(`JSON array is not supported in ${_id}, moving the array into the \`body\` key`);
|
|
19
|
+
parsed = {
|
|
20
|
+
body: parsed
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...parsed,
|
|
25
|
+
_id,
|
|
26
|
+
_type: "json"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { parseMarkdown } from "@nuxtjs/mdc/runtime";
|
|
2
|
+
import { normalizeUri } from "micromark-util-sanitize-uri";
|
|
3
|
+
import { isRelative } from "ufo";
|
|
4
|
+
import { defineTransformer } from "./utils.js";
|
|
5
|
+
import { generatePath } from "./path-meta.js";
|
|
6
|
+
export default defineTransformer({
|
|
7
|
+
name: "markdown",
|
|
8
|
+
extensions: [".md"],
|
|
9
|
+
parse: async (_id, content, options = {}) => {
|
|
10
|
+
const config = { ...options };
|
|
11
|
+
config.rehypePlugins = await importPlugins(config.rehypePlugins);
|
|
12
|
+
config.remarkPlugins = await importPlugins(config.remarkPlugins);
|
|
13
|
+
const highlightOptions = options.highlight ? {
|
|
14
|
+
...options.highlight,
|
|
15
|
+
// Pass only when it's an function. String values are handled by `@nuxtjs/mdc`
|
|
16
|
+
highlighter: typeof options.highlight?.highlighter === "function" ? options.highlight.highlighter : void 0
|
|
17
|
+
} : void 0;
|
|
18
|
+
const parsed = await parseMarkdown(content, {
|
|
19
|
+
...config,
|
|
20
|
+
highlight: highlightOptions,
|
|
21
|
+
remark: {
|
|
22
|
+
plugins: config.remarkPlugins
|
|
23
|
+
},
|
|
24
|
+
rehype: {
|
|
25
|
+
options: {
|
|
26
|
+
handlers: {
|
|
27
|
+
link
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
plugins: config.rehypePlugins
|
|
31
|
+
},
|
|
32
|
+
toc: config.toc
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
...parsed.data,
|
|
36
|
+
excerpt: parsed.excerpt,
|
|
37
|
+
body: {
|
|
38
|
+
...parsed.body,
|
|
39
|
+
toc: parsed.toc
|
|
40
|
+
},
|
|
41
|
+
_type: "markdown",
|
|
42
|
+
_id
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
async function importPlugins(plugins = {}) {
|
|
47
|
+
const resolvedPlugins = {};
|
|
48
|
+
for (const [name, plugin] of Object.entries(plugins)) {
|
|
49
|
+
if (plugin) {
|
|
50
|
+
resolvedPlugins[name] = {
|
|
51
|
+
instance: plugin.instance || await import(
|
|
52
|
+
/* @vite-ignore */
|
|
53
|
+
name
|
|
54
|
+
).then((m) => m.default || m),
|
|
55
|
+
options: plugin
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
resolvedPlugins[name] = false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return resolvedPlugins;
|
|
62
|
+
}
|
|
63
|
+
function link(state, node) {
|
|
64
|
+
const properties = {
|
|
65
|
+
...node.attributes || {},
|
|
66
|
+
href: normalizeUri(normalizeLink(node.url))
|
|
67
|
+
};
|
|
68
|
+
if (node.title !== null && node.title !== void 0) {
|
|
69
|
+
properties.title = node.title;
|
|
70
|
+
}
|
|
71
|
+
const result = {
|
|
72
|
+
type: "element",
|
|
73
|
+
tagName: "a",
|
|
74
|
+
properties,
|
|
75
|
+
children: state.all(node)
|
|
76
|
+
};
|
|
77
|
+
state.patch(node, result);
|
|
78
|
+
return state.applyData(node, result);
|
|
79
|
+
}
|
|
80
|
+
function normalizeLink(link2) {
|
|
81
|
+
const match = link2.match(/#.+$/);
|
|
82
|
+
const hash = match ? match[0] : "";
|
|
83
|
+
if (link2.replace(/#.+$/, "").endsWith(".md") && (isRelative(link2) || !/^https?/.test(link2) && !link2.startsWith("/"))) {
|
|
84
|
+
return generatePath(link2.replace(".md" + hash, ""), { forceLeadingSlash: false }) + hash;
|
|
85
|
+
} else {
|
|
86
|
+
return link2;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const describeId: (id: string) => {
|
|
2
|
+
_source: string | undefined;
|
|
3
|
+
_path: string;
|
|
4
|
+
_extension: string | undefined;
|
|
5
|
+
_file: string;
|
|
6
|
+
_basename: string;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: ContentTransformer;
|
|
9
|
+
export default _default;
|
|
10
|
+
/**
|
|
11
|
+
* Generate path from file name
|
|
12
|
+
*
|
|
13
|
+
* @param path file full path
|
|
14
|
+
* @returns generated slug
|
|
15
|
+
*/
|
|
16
|
+
export declare const generatePath: (path: string, { forceLeadingSlash, respectPathCase }?: {
|
|
17
|
+
forceLeadingSlash?: boolean | undefined;
|
|
18
|
+
respectPathCase?: boolean | undefined;
|
|
19
|
+
}) => string;
|
|
20
|
+
/**
|
|
21
|
+
* generate title from file path
|
|
22
|
+
*/
|
|
23
|
+
export declare const generateTitle: (path: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Clean up special keywords from path part
|
|
26
|
+
*/
|
|
27
|
+
export declare function refineUrlPart(name: string): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { pascalCase } from "scule";
|
|
2
|
+
import slugify from "slugify";
|
|
3
|
+
import { withoutTrailingSlash, withLeadingSlash } from "ufo";
|
|
4
|
+
import { defineTransformer } from "./utils.js";
|
|
5
|
+
const SEMVER_REGEX = /^(\d+)(\.\d+)*(\.x)?$/;
|
|
6
|
+
export const describeId = (id) => {
|
|
7
|
+
const [_source, ...parts] = id.split(":");
|
|
8
|
+
const [, basename, _extension] = parts[parts.length - 1]?.match(/(.*)\.([^.]+)$/) || [];
|
|
9
|
+
if (basename) {
|
|
10
|
+
parts[parts.length - 1] = basename;
|
|
11
|
+
}
|
|
12
|
+
const _path = (parts || []).join("/");
|
|
13
|
+
return {
|
|
14
|
+
_source,
|
|
15
|
+
_path,
|
|
16
|
+
_extension,
|
|
17
|
+
_file: _extension ? `${_path}.${_extension}` : _path,
|
|
18
|
+
_basename: basename || ""
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export default defineTransformer({
|
|
22
|
+
name: "path-meta",
|
|
23
|
+
extensions: [".*"],
|
|
24
|
+
transform(content, options = {}) {
|
|
25
|
+
const { locales = [], defaultLocale = "en", respectPathCase = false } = options;
|
|
26
|
+
const { _source, _file, _path, _extension, _basename } = describeId(content._id);
|
|
27
|
+
const parts = _path.split("/");
|
|
28
|
+
const _locale = locales.includes(parts[0]) ? parts.shift() : defaultLocale;
|
|
29
|
+
const filePath = generatePath(parts.join("/"), { respectPathCase });
|
|
30
|
+
return {
|
|
31
|
+
_path: filePath,
|
|
32
|
+
_dir: filePath.split("/").slice(-2)[0],
|
|
33
|
+
_draft: content._draft || content.draft || isDraft(_path),
|
|
34
|
+
_partial: isPartial(_path),
|
|
35
|
+
_locale,
|
|
36
|
+
...content,
|
|
37
|
+
// TODO: move title to Markdown parser
|
|
38
|
+
title: content.title || generateTitle(refineUrlPart(_basename)),
|
|
39
|
+
_source,
|
|
40
|
+
_file,
|
|
41
|
+
_stem: _path,
|
|
42
|
+
_extension
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const isDraft = (path) => !!path.match(/\.draft(\/|\.|$)/);
|
|
47
|
+
const isPartial = (path) => path.split(/[:/]/).some((part) => part.match(/^_.*/));
|
|
48
|
+
export const generatePath = (path, { forceLeadingSlash = true, respectPathCase = false } = {}) => {
|
|
49
|
+
path = path.split("/").map((part) => slugify(refineUrlPart(part), { lower: !respectPathCase })).join("/");
|
|
50
|
+
return forceLeadingSlash ? withLeadingSlash(withoutTrailingSlash(path)) : path;
|
|
51
|
+
};
|
|
52
|
+
export const generateTitle = (path) => path.split(/[\s-]/g).map(pascalCase).join(" ");
|
|
53
|
+
export function refineUrlPart(name) {
|
|
54
|
+
name = name.split(/[/:]/).pop();
|
|
55
|
+
if (SEMVER_REGEX.test(name)) {
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
return name.replace(/(\d+\.)?(.*)/, "$2").replace(/^index(\.draft)?$/, "").replace(/\.draft$/, "");
|
|
59
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ContentTransformer } from '@nuxt/content';
|
|
2
|
+
export declare const defineTransformer: (transformer: ContentTransformer) => ContentTransformer;
|
|
3
|
+
export declare const createSingleton: <T, Params extends Array<any>>(fn: (...arg: Params) => T) => (...args: Params) => T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { parseFrontMatter } from "remark-mdc";
|
|
2
|
+
import { defineTransformer } from "./utils.js";
|
|
3
|
+
export default defineTransformer({
|
|
4
|
+
name: "Yaml",
|
|
5
|
+
extensions: [".yml", ".yaml"],
|
|
6
|
+
parse: (_id, content) => {
|
|
7
|
+
const { data } = parseFrontMatter(`---
|
|
8
|
+
${content}
|
|
9
|
+
---`);
|
|
10
|
+
let parsed = data;
|
|
11
|
+
if (Array.isArray(data)) {
|
|
12
|
+
console.warn(`YAML array is not supported in ${_id}, moving the array into the \`body\` key`);
|
|
13
|
+
parsed = { body: data };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...parsed,
|
|
17
|
+
_id,
|
|
18
|
+
_type: "yaml"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
"a",
|
|
3
|
+
"abbr",
|
|
4
|
+
"address",
|
|
5
|
+
"area",
|
|
6
|
+
"article",
|
|
7
|
+
"aside",
|
|
8
|
+
"audio",
|
|
9
|
+
"b",
|
|
10
|
+
"base",
|
|
11
|
+
"bdi",
|
|
12
|
+
"bdo",
|
|
13
|
+
"blockquote",
|
|
14
|
+
"body",
|
|
15
|
+
"br",
|
|
16
|
+
"button",
|
|
17
|
+
"canvas",
|
|
18
|
+
"caption",
|
|
19
|
+
"cite",
|
|
20
|
+
"code",
|
|
21
|
+
"col",
|
|
22
|
+
"colgroup",
|
|
23
|
+
"data",
|
|
24
|
+
"datalist",
|
|
25
|
+
"dd",
|
|
26
|
+
"del",
|
|
27
|
+
"details",
|
|
28
|
+
"dfn",
|
|
29
|
+
"dialog",
|
|
30
|
+
"div",
|
|
31
|
+
"dl",
|
|
32
|
+
"dt",
|
|
33
|
+
"em",
|
|
34
|
+
"embed",
|
|
35
|
+
"fieldset",
|
|
36
|
+
"figcaption",
|
|
37
|
+
"figure",
|
|
38
|
+
"footer",
|
|
39
|
+
"form",
|
|
40
|
+
"h1",
|
|
41
|
+
"h2",
|
|
42
|
+
"h3",
|
|
43
|
+
"h4",
|
|
44
|
+
"h5",
|
|
45
|
+
"h6",
|
|
46
|
+
"head",
|
|
47
|
+
"header",
|
|
48
|
+
"hgroup",
|
|
49
|
+
"hr",
|
|
50
|
+
"html",
|
|
51
|
+
"i",
|
|
52
|
+
"iframe",
|
|
53
|
+
"img",
|
|
54
|
+
"input",
|
|
55
|
+
"ins",
|
|
56
|
+
"kbd",
|
|
57
|
+
"label",
|
|
58
|
+
"legend",
|
|
59
|
+
"li",
|
|
60
|
+
"link",
|
|
61
|
+
"main",
|
|
62
|
+
"map",
|
|
63
|
+
"mark",
|
|
64
|
+
"math",
|
|
65
|
+
"menu",
|
|
66
|
+
"menuitem",
|
|
67
|
+
"meta",
|
|
68
|
+
"meter",
|
|
69
|
+
"nav",
|
|
70
|
+
"noscript",
|
|
71
|
+
"object",
|
|
72
|
+
"ol",
|
|
73
|
+
"optgroup",
|
|
74
|
+
"option",
|
|
75
|
+
"output",
|
|
76
|
+
"p",
|
|
77
|
+
"param",
|
|
78
|
+
"picture",
|
|
79
|
+
"pre",
|
|
80
|
+
"progress",
|
|
81
|
+
"q",
|
|
82
|
+
"rb",
|
|
83
|
+
"rp",
|
|
84
|
+
"rt",
|
|
85
|
+
"rtc",
|
|
86
|
+
"ruby",
|
|
87
|
+
"s",
|
|
88
|
+
"samp",
|
|
89
|
+
"script",
|
|
90
|
+
"section",
|
|
91
|
+
"select",
|
|
92
|
+
"slot",
|
|
93
|
+
"small",
|
|
94
|
+
"source",
|
|
95
|
+
"span",
|
|
96
|
+
"strong",
|
|
97
|
+
"style",
|
|
98
|
+
"sub",
|
|
99
|
+
"summary",
|
|
100
|
+
"sup",
|
|
101
|
+
"svg",
|
|
102
|
+
"table",
|
|
103
|
+
"tbody",
|
|
104
|
+
"td",
|
|
105
|
+
"template",
|
|
106
|
+
"textarea",
|
|
107
|
+
"tfoot",
|
|
108
|
+
"th",
|
|
109
|
+
"thead",
|
|
110
|
+
"time",
|
|
111
|
+
"title",
|
|
112
|
+
"tr",
|
|
113
|
+
"track",
|
|
114
|
+
"u",
|
|
115
|
+
"ul",
|
|
116
|
+
"var",
|
|
117
|
+
"video",
|
|
118
|
+
"wbr"
|
|
119
|
+
];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
|
|
3
|
+
* This function is equivalent to `JSON.stringify`, but it also handles RegExp objects.
|
|
4
|
+
*/
|
|
5
|
+
export declare function jsonStringify(value: any): string;
|
|
6
|
+
/**
|
|
7
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
8
|
+
* This function is equivalent to `JSON.parse`, but it also handles RegExp objects.
|
|
9
|
+
*/
|
|
10
|
+
export declare function jsonParse(value: string): any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function jsonStringify(value) {
|
|
2
|
+
return JSON.stringify(value, regExpReplacer);
|
|
3
|
+
}
|
|
4
|
+
export function jsonParse(value) {
|
|
5
|
+
return JSON.parse(value, regExpReviver);
|
|
6
|
+
}
|
|
7
|
+
function regExpReplacer(_key, value) {
|
|
8
|
+
if (value instanceof RegExp) {
|
|
9
|
+
return `--REGEX ${value.toString()}`;
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function regExpReviver(_key, value) {
|
|
14
|
+
const withOperator = typeof value === "string" && value.match(/^--([A-Z]+) (.+)$/) || [];
|
|
15
|
+
if (withOperator[1] === "REGEX") {
|
|
16
|
+
const regex = withOperator[2]?.match(/\/(.*)\/([dgimsuy]*)$/);
|
|
17
|
+
return regex?.[1] ? new RegExp(regex[1], regex[2] || "") : value;
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type H3Event } from 'h3';
|
|
2
|
+
import type { ContentQueryBuilderParams } from '@nuxt/content';
|
|
3
|
+
export declare const encodeQueryParams: (params: ContentQueryBuilderParams) => string;
|
|
4
|
+
export declare const decodeQueryParams: (encoded: string) => any;
|
|
5
|
+
export declare const getContentQuery: (event: H3Event) => ContentQueryBuilderParams;
|