2018-07-22 14:52:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$redirects = array(
|
|
|
|
{% for from, to in redirects.items() %}
|
|
|
|
"{{ from }}" => "{{ to }}",
|
|
|
|
{% endfor %}
|
|
|
|
);
|
|
|
|
|
2019-08-12 10:49:51 +01:00
|
|
|
$rewrites = array(
|
|
|
|
{% for from, to in rewrites.items() %}
|
|
|
|
"{{ from }}" => "{{ to }}",
|
|
|
|
{% endfor %}
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
);
|
|
|
|
|
2018-07-22 14:52:32 +01:00
|
|
|
$gone = array(
|
|
|
|
{% for gone in gones %}
|
|
|
|
"{{ gone }}" => true,
|
|
|
|
{% endfor %}
|
|
|
|
);
|
|
|
|
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
$gone_re = array(
|
2019-08-12 10:49:51 +01:00
|
|
|
{% for gone in gone_re %}
|
|
|
|
"{{ gone }}",
|
|
|
|
{% endfor %}
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
);
|
|
|
|
|
2018-07-22 14:52:32 +01:00
|
|
|
function redirect_to($uri) {
|
|
|
|
header('HTTP/1.1 301 Moved Permanently');
|
|
|
|
if (preg_match("/^https?/", $uri))
|
|
|
|
$target = $uri;
|
|
|
|
else
|
|
|
|
$target = '{{ site.url }}/'. trim($uri, '/') . '/';
|
|
|
|
header("Location: ". $target);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gone($uri) {
|
|
|
|
header('HTTP/1.1 410 Gone');
|
|
|
|
die('<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8"/>
|
|
|
|
<meta content="width=device-width,initial-scale=1,minimum-scale=1" name="viewport"/>
|
|
|
|
<title>Gone</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1><center>This content was deleted.</center></h1>
|
|
|
|
<hr>
|
2019-02-16 00:14:12 +00:00
|
|
|
<p><center>'.$uri.'</center></p>
|
2018-07-22 14:52:32 +01:00
|
|
|
</body>
|
|
|
|
</html>');
|
|
|
|
}
|
|
|
|
|
2019-02-16 00:14:12 +00:00
|
|
|
function notfound($uri) {
|
2018-07-22 14:52:32 +01:00
|
|
|
header('HTTP/1.0 404 Not Found');
|
|
|
|
die('<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8"/>
|
|
|
|
<meta content="width=device-width,initial-scale=1,minimum-scale=1" name="viewport"/>
|
|
|
|
<title>Not found</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h1><center>This was not found.</center></h1>
|
|
|
|
<h2><center>Please search for it instead.</center></h2>
|
|
|
|
<p>
|
|
|
|
<center>
|
2019-02-16 00:14:12 +00:00
|
|
|
<form action="/search.php" class="search-form" method="get" role="search">
|
|
|
|
<label for="search">Search</label>
|
|
|
|
<input id="q" name="q" placeholder="search..." title="Search for:" type="search" value=""/>
|
|
|
|
<input type="submit" value="OK"/>
|
|
|
|
</form>
|
2018-07-22 14:52:32 +01:00
|
|
|
</center>
|
|
|
|
</p>
|
2019-02-16 00:14:12 +00:00
|
|
|
<hr>
|
|
|
|
<p><center>'.$uri.'</center></p>
|
2018-07-22 14:52:32 +01:00
|
|
|
</body>
|
|
|
|
</html>');
|
|
|
|
}
|
|
|
|
|
|
|
|
function maybe_redirect($uri) {
|
|
|
|
if (file_exists("./$uri/index.html")) {
|
|
|
|
redirect_to($uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$uri = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);
|
|
|
|
$uri = str_replace('../', '', $uri);
|
|
|
|
$uri = str_replace('/feed/', '', $uri);
|
|
|
|
$uri = str_replace('/atom/', '', $uri);
|
|
|
|
$uri = trim($uri, '/');
|
|
|
|
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
foreach ($gone_re as $pattern) {
|
|
|
|
if (preg_match(sprintf('/%s/', $pattern), $uri)) {
|
|
|
|
gone($uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 10:49:51 +01:00
|
|
|
foreach ($rewrites as $pattern => $target) {
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
$maybe = preg_match(sprintf('/%s/i', $pattern), $uri, $matches);
|
|
|
|
if ($maybe) {
|
|
|
|
$target = str_replace('$1', $matches[1], $target);
|
|
|
|
redirect_to($target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($gone[$uri])) {
|
2018-07-22 14:52:32 +01:00
|
|
|
gone($uri);
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
}
|
|
|
|
elseif (isset($redirects[$uri])) {
|
2018-07-22 14:52:32 +01:00
|
|
|
redirect_to($redirects[$uri]);
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
}
|
|
|
|
elseif (strstr($uri, '_')) {
|
2018-07-22 14:52:32 +01:00
|
|
|
maybe_redirect(str_replace('_', '-', $uri));
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-02-16 00:14:12 +00:00
|
|
|
notfound($uri);
|
Back To Pandoc
So, Python Markdown is a bottomless pit of horrors, including crippling parsing bugs,
random out of nowhere, lack of features. It's definitely much faster, than
Pandoc, but Pandoc doesn't go full retard where there's a regex in a fenced code block,
that happens to be a regex for markdown elements.
Also added some ugly post string replacements to make Pandoc fenced code output work
with Prism:
instead of the Pandoc <pre class="codelang"><code>, Prism wants
<pre><code class="language-codelang>, so I added a regex sub, because it's 00:32.
2018-08-04 00:28:55 +01:00
|
|
|
}
|