"Invalid URL" 使用 Nuxt 内容模块的降价文件错误
"Invalid URL" error for markdown file using Nuxt content module
我正在 Nuxt 网站上工作,使用 Debbie O'Brien 内置的 content module, and running locally, everything works fine. However, when I attempt to build the site by running nuxt generate
, I get a fatal error on the first markdown file that says Invalid URL
. My markdown files are in the /content/posts
directory, and the name of this one is structured my-post-markdown-file
and named my-post-markdown-file.md
. I've removed the problem file from the directory to see if it was just that particular file, but the process errors out on the next file, too. I'm following this post 来使用内容模块,所以看起来我已经正确创建了东西。还有什么我想念的吗?
更新: 我将范围缩小到站点地图生成。在 this post 之后,我定义了以下用于生成路由的插件:
export default async () => {
const { $content } = require("@nuxt/content");
const files = await $content({ deep: true }).only(["path"]).fetch();
return files.map((file) => (file.path === "/index" ? "/" : file.path));
};
然后在我的 nuxt.config.js
中,我将站点地图定义为
sitemap: {
path: '/sitemap.xml',
hostname: process.env.BASE_URL,
gzip: true,
routes() {
return getRoutes();
}
}
我的内容目录结构是
content
| \
| posts
| \
| my-post-markdown-file1.md
| my-post-markdown-file2.md
| my-post-markdown-file3.md
about.md
当我 运行 npm generate
它以这个错误结束
TypeError [ERR_INVALID_URL]: Invalid URL: about
在 nuxt.config.js
中使用此配置,我能够使用内容模块为我的 Nuxt 站点生成站点地图:
sitemap: {
hostname: 'https://my-website-url.com',
gzip: true,
routes: async () => {
let routes = []
const { $content } = require('@nuxt/content')
let posts = await $content('posts').fetch()
for (const post of posts) {
routes.push(`blog/${post.slug}`)
}
return routes
},
},
我在本地构建和部署到 Netlify 时都对此进行了测试。
我看到的一个可能不同的配置是您正在 returning 的路由可能不是有效的端点。路由的 return 应该是一组有效的相对 URL。您是否将博客 post 托管为“https://url.com/{post}”?
我正在 Nuxt 网站上工作,使用 Debbie O'Brien 内置的 content module, and running locally, everything works fine. However, when I attempt to build the site by running nuxt generate
, I get a fatal error on the first markdown file that says Invalid URL
. My markdown files are in the /content/posts
directory, and the name of this one is structured my-post-markdown-file
and named my-post-markdown-file.md
. I've removed the problem file from the directory to see if it was just that particular file, but the process errors out on the next file, too. I'm following this post 来使用内容模块,所以看起来我已经正确创建了东西。还有什么我想念的吗?
更新: 我将范围缩小到站点地图生成。在 this post 之后,我定义了以下用于生成路由的插件:
export default async () => {
const { $content } = require("@nuxt/content");
const files = await $content({ deep: true }).only(["path"]).fetch();
return files.map((file) => (file.path === "/index" ? "/" : file.path));
};
然后在我的 nuxt.config.js
中,我将站点地图定义为
sitemap: {
path: '/sitemap.xml',
hostname: process.env.BASE_URL,
gzip: true,
routes() {
return getRoutes();
}
}
我的内容目录结构是
content
| \
| posts
| \
| my-post-markdown-file1.md
| my-post-markdown-file2.md
| my-post-markdown-file3.md
about.md
当我 运行 npm generate
它以这个错误结束
TypeError [ERR_INVALID_URL]: Invalid URL: about
在 nuxt.config.js
中使用此配置,我能够使用内容模块为我的 Nuxt 站点生成站点地图:
sitemap: {
hostname: 'https://my-website-url.com',
gzip: true,
routes: async () => {
let routes = []
const { $content } = require('@nuxt/content')
let posts = await $content('posts').fetch()
for (const post of posts) {
routes.push(`blog/${post.slug}`)
}
return routes
},
},
我在本地构建和部署到 Netlify 时都对此进行了测试。
我看到的一个可能不同的配置是您正在 returning 的路由可能不是有效的端点。路由的 return 应该是一组有效的相对 URL。您是否将博客 post 托管为“https://url.com/{post}”?