gatsby - Gatsby MDX slugs 无法导航,名称中包含目录
问题描述
创建的 Slugs 包含根目录,因此传递 slug 到<Link to={slug}>
被破坏。页面已创建,但链接到它们的 slug 不必要地包含包含文件夹,无论是帖子还是页面。
可导航的页面是:
localhost:8000/test-mdx-1/
localhost:8000/posts/test-mdx-2/
localhost:8000/test-mdx-3/
文件位置是:
./src/posts/test-mdx-1.mdx
./src/pages/posts/test-mdx-2.mdx
./src/pages/test-mdx-3.mdx
** 问题 - 创建 slug **
slug: "posts/test-mdx-1/"
slug: "pages/posts/test-mdx-2/"
slug: "pages/test-mdx-3/"
** 期望的结果 **
slug: "test-mdx-1/"
slug: "posts/test-mdx-2/"
slug: "test-mdx-3/"
使用插件:
{
resolve: 'gatsby-plugin-mdx',
options: {
extensions: [`.mdx`],
gatsbyRemarkPlugins: [
{
resolve: 'gatsby-remark-images',
options: { maxWidth: 600 },
},
{
resolve: `gatsby-remark-responsive-iframe`,
options: {
wrapperStyle: `margin-bottom: 1.0725rem`,
},
},
],
},
},
// ** as per tutorial
{
resolve: 'gatsby-source-filesystem',
options: {
name: `pages`,
path: `${__dirname}/src/pages`,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: `posts`,
path: `${__dirname}/src/posts`,
},
},
// ** Create mdx pages outside of ./src/pages directory
{
resolve: 'gatsby-plugin-page-creator',
options: {
path: `${__dirname}/src/posts`,
},
},
解决方案
已排序 - 只需要 1 个 gatsby-source-filesystem,将所有 .mdx 文件移动到 ./src/posts
盖茨比-config.js
...
{
resolve: 'gatsby-plugin-mdx',
options: {
extensions: [`.mdx`],
gatsbyRemarkPlugins: [
{
resolve: 'gatsby-remark-images',
options: { maxWidth: 600 },
},
{
resolve: `gatsby-remark-responsive-iframe`,
options: {
wrapperStyle: `margin-bottom: 1.0725rem`,
},
},
],
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: `posts`,
path: `${__dirname}/src/posts`,
},
},
// ** Create mdx pages outside of ./src/pages directory
{
resolve: 'gatsby-plugin-page-creator',
options: {
path: `${__dirname}/src/posts`,
},
},
...
推荐阅读
- quickbooks - 快速书关闭时 Web 连接器未连接
- bash - BASH 比较两个字段集成来自另一个文件的信息
- javascript - 更改单元格时如何刷新自定义剑道网格过滤器
- javascript - 如何使用基本身份验证存储 Web 服务调用的凭据
- javascript - 如果没有提供 reduce ,它如何决定它的初始值?
- c - 给定到插值点的距离,如何在一条线上插值点的位置
- jquery - Jquery Select2 不适用于动态字段
- c++ - Qt(QVBoxLayout 类)中的小部件何时被删除?
- php - 致命错误:无法在写入上下文错误中使用函数返回值
- javascript - TypeError: undefined is not a constructor (evalating 'casper.done()') 错误