@mdream/nuxt 0.12.0 → 0.12.2
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/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { consola } from 'consola';
|
|
|
7
7
|
import { generateLlmsTxtArtifacts } from 'mdream/llms-txt';
|
|
8
8
|
|
|
9
9
|
const name = "@mdream/nuxt";
|
|
10
|
-
const version = "0.12.
|
|
10
|
+
const version = "0.12.2";
|
|
11
11
|
|
|
12
12
|
const logger = consola.withTag("nuxt-mdream");
|
|
13
13
|
function setupPrerenderHandler() {
|
|
@@ -57,6 +57,9 @@ async function convertHtmlToMarkdown(html, url, config, route, event) {
|
|
|
57
57
|
export default defineEventHandler(async (event) => {
|
|
58
58
|
let path = event.path;
|
|
59
59
|
const config = useRuntimeConfig(event).mdream;
|
|
60
|
+
if (path.startsWith("/api") || path.startsWith("/_") || path.endsWith(".html")) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
60
63
|
const hasMarkdownExtension = path.endsWith(".md");
|
|
61
64
|
const clientPrefersMarkdown = shouldServeMarkdown(event);
|
|
62
65
|
if (!hasMarkdownExtension && !clientPrefersMarkdown) {
|
|
@@ -70,14 +73,39 @@ export default defineEventHandler(async (event) => {
|
|
|
70
73
|
}
|
|
71
74
|
let html;
|
|
72
75
|
try {
|
|
73
|
-
|
|
76
|
+
const response = await globalThis.$fetch.raw(path);
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
if (hasMarkdownExtension) {
|
|
79
|
+
return createError({
|
|
80
|
+
statusCode: response.status,
|
|
81
|
+
statusMessage: response.statusText,
|
|
82
|
+
message: `Failed to fetch HTML for ${path}`
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const contentType = response.headers.get("content-type") || "";
|
|
88
|
+
if (!contentType.includes("text/html")) {
|
|
89
|
+
if (hasMarkdownExtension) {
|
|
90
|
+
return createError({
|
|
91
|
+
statusCode: 415,
|
|
92
|
+
statusMessage: "Unsupported Media Type",
|
|
93
|
+
message: `Expected text/html but got ${contentType} for ${path}`
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
html = response._data;
|
|
74
99
|
} catch (e) {
|
|
75
100
|
logger.error(`Failed to fetch HTML for ${path}`, e);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
if (hasMarkdownExtension) {
|
|
102
|
+
return createError({
|
|
103
|
+
statusCode: 500,
|
|
104
|
+
statusMessage: "Internal Server Error",
|
|
105
|
+
message: `Failed to fetch HTML for ${path}`
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
81
109
|
}
|
|
82
110
|
const result = await convertHtmlToMarkdown(
|
|
83
111
|
html,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdream/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.2",
|
|
5
5
|
"description": "Nuxt module for converting HTML pages to Markdown using mdream",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"defu": "^6.1.4",
|
|
39
39
|
"nuxt-site-config": "^3.2.9",
|
|
40
40
|
"pathe": "^2.0.3",
|
|
41
|
-
"mdream": "0.12.
|
|
41
|
+
"mdream": "0.12.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@antfu/eslint-config": "^5.4.1",
|