-
Notifications
You must be signed in to change notification settings - Fork 1
/
random.html
50 lines (50 loc) · 1.61 KB
/
random.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
# Jekyll page that redirects to a random page, post or document
# https://github.com/jekylltools/jekyll-random-redirect
# v1.6
title: Random
layout: none
permalink: /random/
---
{%- assign docs = site.posts -%}
{%- if site.random_redirect.pages == true -%}
{%- assign pages = site.html_pages | where_exp:"page","page.url != '/random/'" -%}
{%- assign docs = docs | concat: pages -%}
{%- endif -%}
{%- if site.random_redirect.documents == true -%}
{%- assign docs = docs | concat: site.documents | uniq -%}
{%- endif -%}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
var urls=[];
{% for doc in docs -%}
urls.push("{{ doc.url | absolute_url }}");
{% endfor -%}
var url = urls[Math.floor(Math.random()*urls.length)];
var link = document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', url);
document.head.appendChild(link);
if (typeof IE_fix != "undefined") {
document.write("Redirecting...");
var referLink = document.createElement("a");
referLink.href = url;
document.body.appendChild(referLink);
referLink.click();
} else {
window.location.replace(url);
}
</script>
<title>Redirecting...</title>
</head>
<body>
<noscript>JavaScript is required to load a random page for you.<br>
Please enable JavaScript, then refresh this page.<br><br>
<a href="{{ site.url }}">Go back home...</a>
</noscript>
</body>
</html>