如何使用 github-pages 从 pdf 文件重定向?

Ale*_*lex 3 jekyll github-pages

我正在尝试从一个 pdf 文件重定向到另一个 pdf 文件。因此,例如:

https://my-site.com/the-first-file.pdf
Run Code Online (Sandbox Code Playgroud)

应该重定向到

https://my-site.com/the-second-file.pdf
Run Code Online (Sandbox Code Playgroud)

我查看了github上关于重定向的文档,但我无法将该元数据添加到 pdf 文件中...

任何帮助表示赞赏!

Cai*_*ete 5

另一种(在我看来稍微更好的)方法是模仿它的作用jekyll-redirect,使用meta http-equiv="refresh"标签要求浏览器重定向用户,这不需要 JavaScript。

即您将删除并创建一个名为以下内​​容的the-first-file.pdf文件:the-first-file.pdf.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting...</title>
<link rel="canonical" href="https://my-site.com/the-second-file.pdf">
<meta http-equiv="refresh" content="0; url=https://my-site.com/the-second-file.pdf">
<h1>Redirecting...</h1>
<a href="https://my-site.com/the-second-file.pdf">Click here if you are not redirected.</a>
<script>location="https://my-site.com/the-second-file.pdf"</script>
Run Code Online (Sandbox Code Playgroud)

更好的是,您可以利用 Jekyll 生成此文件的优势,并使用站点变量根据配置设置构建 URL(当然,您也可以在 javascript 版本中执行此操作):

---
---
<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting...</title>
{% assign redirect_url = "/the-second-file.pdf" | prepend: site.baseurl | prepend: site.url %}
<link rel="canonical" href="{{ redirect_url }}">
<meta http-equiv="refresh" content="0; url={{ redirect_url }}">
<h1>Redirecting...</h1>
<a href="{{ redirect_url }}">Click here if you are not redirected.</a>
<script>location="{{ redirect_url }}"</script>
Run Code Online (Sandbox Code Playgroud)