目前,Vuepress permalinks只能在给定的模板变量上进行自定义。例如,给定以下目录结构:
posts
coding
my_post.md使用固定链接/:regular,我得到了/posts/coding/my_post.md。然而,由于迁移和现有的搜索引擎优化问题,我需要这个链接是/coding/my_post.md。有没有办法更改在Vuepress blog plugin中生成的链接
发布于 2021-01-25 00:23:01
不幸的是,除了模板变量之外,没有明确的方法来定制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的文章,那里有更多关于如何扩展页面数据以及如何修改固定链接的文档。
https://stackoverflow.com/questions/65870707
复制相似问题