Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[功能建议]文章永久链接 #237

Open
1 task done
arcoe opened this issue Jun 5, 2023 · 8 comments
Open
1 task done

[功能建议]文章永久链接 #237

arcoe opened this issue Jun 5, 2023 · 8 comments
Assignees
Labels
enhancement New feature or request pr welcome

Comments

@arcoe
Copy link

arcoe commented Jun 5, 2023

我在看valaxy文档时,似乎并没有看到永久链接相关的功能

相关链接:

@arcoe arcoe added the enhancement New feature or request label Jun 5, 2023
@YunYouJun YunYouJun self-assigned this Jun 11, 2023
@YunYouJun
Copy link
Owner

valaxy 的链接取决于你新建文件的标题名,同一个文件夹下并不会存在多个文件。在我看来,这已经解决了链接唯一性的问题,此外我认为语义化的链接也更为优雅。

你所期待的需求是什么?

@mirari
Copy link

mirari commented Sep 1, 2023

从hexo迁移后,原本文章的永久链接比如a.com/2023/09/01/foobar会变成a.com/posts/2023-09-01-foobar
以前在其他地方做的跳转都会失效,逐个修改会比较麻烦,甚至有些是没法修改的。
是否有办法实现地址映射,将原本hexo规则的URL指向新的地址?
单纯的静态部署似乎没法支持,或者是在对应路径生成同名落地页然后跳转?

@YunYouJun
Copy link
Owner

YunYouJun commented Sep 3, 2023

可以放置在 /2023/09/01 的文件夹下。

或是新建 __redirects (cloudflare 和 netlify 支持)添加重定向。

/rss https://yyj.moe/feed.xml 301
/blog https://yunyoujun.cn 301

/github https://github.com/YunYouJun 301
/twitter https://twitter.com/YunYouJun 301
/sponsors https://sponsors.yunyoujun.cn 301
/live https://live.bilibili.com/822719 301

地址映射在 Valaxy 的未来开发计划中,但暂时还未实现。(得再等一等了,或者欢迎 PR。

@mirari
Copy link

mirari commented Sep 6, 2023

因为博客迁移,这几天谷歌广告和谷歌搜索都报了好多404错误。
我看现在任何不存在的请求都会被跳转到404.html,是否可以在404落地页面或者router上加个钩子,然后做跳转。

@YunYouJun
Copy link
Owner

因为博客迁移,这几天谷歌广告和谷歌搜索都报了好多404错误。 我看现在任何不存在的请求都会被跳转到404.html,是否可以在404落地页面或者router上加个钩子,然后做跳转。

如果是已经跳转到了 404 页面,这时候再加钩子应该是没用的。

可以做一个 301 redirects。

@YunYouJun
Copy link
Owner

YunYouJun commented Sep 6, 2023

或者你想要的其实是不是就是一个 a -> b 路径的重定向?

感觉也可以通过一个数组脚本来做,批量生产带有 window.location.href = new link 的页面。


https://developers.cloudflare.com/pages/platform/redirects/

cloudflare 支持 redirects 和 proxy。

@mirari
Copy link

mirari commented Sep 7, 2023

我在404.vue落地页做了一个跳转逻辑,如果route.path匹配就跳转,缺点是会先看到404再跳过去

const redirectTarget = redirectList.find(x => {
  const regex = /(\d{4})-(\d{2})-(\d{2})-(.*)/;
  const result = x.from.replace(regex, '/$1/$2/$3/$4');
  return encodeURI(result) === route.path || result === route.path
})
if (redirectTarget) {
  router.replace(`/posts/${redirectTarget.to}`)
}
[
  {
    "from": "2017-08-14-aaa",
    "to": "aaa"
  },
  {
    "from": "2017-08-27-bbb",
    "to": "bbb"
  },
]

github pages应该没办法做301了吧,看来还得迁移到cloudflare去

@YunYouJun
Copy link
Owner

YunYouJun commented Sep 7, 2023

也可以加一个后处理脚本,直接拷贝一下 dist/xxx.html 为 dist/yyy.html。

(貌似这个也可以做个功能

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pr welcome
Projects
None yet
Development

No branches or pull requests

3 participants