cleanup and magic.php

This commit is contained in:
Peter Molnar 2017-05-26 15:09:16 +01:00
parent 0bd85c4518
commit c443c94979
7 changed files with 128 additions and 47 deletions

View file

@ -2,7 +2,7 @@
<footer class="content-footer" id="main-footer">
<div class="limit">
<nav class="footer-contact p-author h-card vcard">
<img class="photo avatar u-photo u-avatar" src="{{ site.author.avatar }}" alt="Photo of {{ site.author.name }}" />
<img class="photo avatar u-photo u-avatar" src="{{ site.url }}/{{ site.author.avatar }}" alt="Photo of {{ site.author.name }}" />
<dl>
<dt>name</dt>
@ -50,4 +50,4 @@
</footer>
</body>
</html>
</html>

View file

@ -1,19 +0,0 @@
{% include 'block_header_open.html' %}
{%- if taxonomy.name -%}
{%- set title = taxonomy.name ~ ' | ' ~ site.name -%}
{%- else -%}
{%- set title = site.name -%}
{%- endif -%}
<title>{{ title }}</title>
{% include 'block_header_close.html' %}
<section class="content-body h-feed">
<div id="justified-gallery">
{% for post in posts %}
{{ post.srcset }}
{% endfor %}
</section>
{% include 'block_footer.html' %}

View file

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html lang="{{ post.lang }}">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1" />
<title>{{ post.title }}</title>
<link rel="self" href="{{ post.realurl }}/" />
<link rel="origin" href="{{ post.url }}/" />
<meta name="summary" content="{{ post.excerpt }}" />
<meta name="byline" content="{{ post.byline }}" />
</head>
<body>
{{ post.html }}
</body>
</html>

90
magic.php Normal file
View file

@ -0,0 +1,90 @@
<?php
function redirect_to($uri) {
header('HTTP/1.1 301 Moved Permanently');
if (preg_match("/^https?/", $uri))
$target = $uri;
else
$target = 'https://petermolnar.net/'. 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>This content was deleted.</h1>
</body>
</html>');
}
function notfound() {
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>This was not found.</h1>
<h2>Please search for it instead.</h2>
<p>
<form action="/search" class="search-form" method="get" role="search">
<label for="search">Search</label>
<input id="s" name="s" placeholder="search..." title="Search for:" type="search" value=""/>
<input type="submit" value="OK"/>
</form>
</p>
</body>
</html>');
}
function maybe_redirect($uri) {
if (file_exists("./{$uri}/index.html")) {
redirect_to($uri);
}
}
$redirects = array(
{% for (from, to) in redirects %}
"{{ from }}" => "{{ to }}",
{%- endfor -%}
);
$gone = array(
{% for gone in gones %}
"{{ gone }}" => true,
{%- endfor -%}
);
$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, '/');
if (isset($gone[$uri]))
gone($uri);
elseif (isset($redirects[$uri]))
redirect_to($redirects[$uri]);
// replace _ with - and look for a file
elseif (strstr($uri, '_'))
maybe_redirect(str_replace('_', '-', $uri));
// try getting rid of -by-xyz
elseif (stristr($uri,'-by-'))
maybe_redirect(preg_replace('/(.*?)-by-.*$/i','${1}',$uri));
// try getting rid of -2, WordPress artifacts
elseif (stristr($uri,'-2'))
maybe_redirect(preg_replace('/(.*?)-2$/i','${1}',$uri));
else
notfound();

View file

@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url={{ url }}" />
</head>
<body>
</body>
</html>

View file

@ -1,12 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1" />
<style media="all">
{% include 'style.css' %}
</style>
<title>Search results for "{{ term }}"</title>
</head>
<body>
<header class="content-header" id="main-header">
<nav class="content-navigation">
<ul>
<li>
<a title="back to site" href="/">
« back to the site
</a>
</li>
</ul>
</nav>
<form role="search" method="get" class="search-form" action="/search">
<label for="search" class="hide">Search</label>
<input type="search" class="search-field" placeholder="search..." value="{{ term }}" name="s" id="s" title="Search for:">
<input type="submit" class="search-submit" value="Go ➡">
</form>
<br class="clear" />
</header>
<section class="content-body">
<h1 class="p-name hide">Search results for "{{ term }}"</h1>
{% if posts|length %}
@ -28,7 +52,7 @@
</header>
<div class="highlight">… {{ post.highlight }} …</div>
{% if post.img %}
{% if post.img and 'None' != post.img %}
<p>{{ post.img }}</p>
{% endif %}
</article>

View file

@ -129,6 +129,15 @@
</p>
</aside>
</footer>
{% if post.offlinecopies %}
{% for url, copy in post.offlinecopies %}
<!-- {{ url }}
{{ copy }}
-->
{% endfor %}
{% endif %}
</article>
<aside class="content-note">
<hr />
@ -141,4 +150,4 @@
</section>
{% include 'block_footer.html' %}
{% include 'block_footer.html' %}