all repos — nasg @ c443c94979bfba5c8011310f578e6e632c98f5b9

cleanup and magic.php
Peter Molnar hello@petermolnar.net
Fri, 26 May 2017 15:09:16 +0100
commit

c443c94979bfba5c8011310f578e6e632c98f5b9

parent

0bd85c45188e222435bb326b13c1777efaf4e77f

7 files changed, 128 insertions(+), 47 deletions(-)

jump to
M block_footer.htmlblock_footer.html

@@ -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 @@ </div>

</footer> </body> -</html>+</html>
D gallery.html

@@ -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' %}
D localcopy.html

@@ -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>
A magic.php

@@ -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();
D redirect.html

@@ -1,8 +0,0 @@

-<!DOCTYPE html> -<html> -<head> - <meta http-equiv="refresh" content="0; url={{ url }}" /> -</head> -<body> -</body> -</html>
M searchresults.htmlsearchresults.html

@@ -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 @@ <h3>{{ post.url }}</h3>

</header> <div class="highlight">… {{ post.highlight }} …</div> - {% if post.img %} + {% if post.img and 'None' != post.img %} <p>{{ post.img }}</p> {% endif %} </article>
M singular.htmlsingular.html

@@ -129,6 +129,15 @@ <a href="{{ site.url }}/{{ post.shortslug }}">{{ site.url }}/{{ post.shortslug }}</a>

</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 @@ </aside>

</section> -{% include 'block_footer.html' %}+{% include 'block_footer.html' %}