如何解决如何在 Vuepress / Vuepress 博客插件中自定义永久链接?
目前,Vuepress permalinks 只能在给定的模板变量上进行自定义。例如,给定以下目录结构:
posts
coding
my_post.md
并使用固定链接 /:regular
我得到 /posts/coding/my_post.md
。但是,由于迁移和现有 SEO 问题,我需要将此链接设为 /coding/my_post.md
。有没有办法改变在 Vuepress blog plugin 中生成的链接?
解决方法
不幸的是,除了模板变量之外,没有明确的方法可以自定义从 Vuepress 或 Vuepress 博客插件生成的永久链接。我找到的一个解决方案是使用一个自定义插件,将永久链接设置为我所需要的:
module.exports = {
extendPageData(pageCtx) {
// We will force permalinks on the posts to be mapped
// to root of the site. So /posts/my_post.md becomes /my_post.html
if (pageCtx.path.startsWith("/posts")) {
pageCtx.frontmatter.permalink = pageCtx.path.replace("/posts","");
}
}
};
并按照 Plugins page 上提供的指南使用插件。此解决方案有效,因为 Vuepress respects the permalink frontmatter。我建议在 plugin options API 上阅读更多内容,其中提供了更多有关如何扩展页面数据以及在这种情况下修改永久链接的文档。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。