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

时间:2016-06-07 16:10:44

标签: jekyll github-pages

我试图从一个pdf文件重定向到另一个。所以,例如:

https://my-site.com/the-first-file.pdf

应该重定向到

https://my-site.com/the-second-file.pdf

我在重定向上查看github's documentation,但我无法将该元数据添加到pdf文件...

任何帮助表示赞赏!

2 个答案:

答案 0 :(得分:1)

另一种(稍微好一点的IMO)方法是模仿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>

更好的是,您可以利用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>

答案 1 :(得分:0)

我发现了一种方法。删除-first-file.pdf并使用以下内容创建名为-first-file.pdf.html的文件:

var rp = require('request-promise'),
    cheerio = require('cheerio'),
    url = require('url'),
    base = 'http://www.google.com';

var options = {
    uri: base,
    method: 'GET',
    resolveWithFullResponse: true
};

rp(options)
  .then (function (response) {
    $ = cheerio.load(response.body);
    var relativeLinks = $("img");
    relativeLinks.each( function() {
        var link = $(this).attr('src');
        var fullImagePath = url.resolve(base, link); // should be absolute 
        console.log(link);
        if (link.startsWith('http')){
            console.log('abs');
        }
        else {
            console.log('rel');
        }
   });
});