Switch to /post/slug format for both blog posts and notes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ee4cc77c85
commit
f2f6293357
@ -38,10 +38,11 @@ function getBlogPosts($params) {
|
||||
$id = intval(substr($file, 0, -3));
|
||||
|
||||
$post = array(
|
||||
"type" => "blog",
|
||||
"title" => $meta["title"],
|
||||
"author" => $meta["author"],
|
||||
"urlrel" => "/blog/".$meta["slug"],
|
||||
"url" => "https://yarmo.eu/blog/".$meta["slug"],
|
||||
"urlrel" => "/post/".$meta["slug"],
|
||||
"url" => "https://yarmo.eu/post/".$meta["slug"],
|
||||
"slug" => $meta["slug"],
|
||||
"date" => $meta["date"],
|
||||
"published" => $meta["published"],
|
||||
@ -90,10 +91,11 @@ function getNotes($params) {
|
||||
$id = intval(substr($file, 0, -3));
|
||||
|
||||
$post = array(
|
||||
"type" => "note",
|
||||
"title" => $meta["title"],
|
||||
"author" => $meta["author"],
|
||||
"urlrel" => "/notes/".$meta["slug"],
|
||||
"url" => "https://yarmo.eu/notes/".$meta["slug"],
|
||||
"urlrel" => "/post/".$meta["slug"],
|
||||
"url" => "https://yarmo.eu/post/".$meta["slug"],
|
||||
"slug" => $meta["slug"],
|
||||
"date" => $meta["date"],
|
||||
"published" => $meta["published"],
|
||||
|
||||
31
index.php
31
index.php
@ -22,6 +22,7 @@ $router->map('GET', '/blog', function() {}, 'blog');
|
||||
$router->map('GET', '/blog/[*:slug]', function() {}, 'blog_post');
|
||||
$router->map('GET', '/notes', function() {}, 'notes');
|
||||
$router->map('GET', '/notes/[*:slug]', function() {}, 'notes_post');
|
||||
$router->map('GET', '/post/[*:slug]', function() {}, 'post');
|
||||
$router->map('GET', '/projects', function() {}, 'projects');
|
||||
$router->map('GET', '/projects/[*:slug]', function() {}, 'projects_details');
|
||||
$router->map('GET', '/foss', function() {}, 'foss');
|
||||
@ -127,12 +128,24 @@ if ($match['name'] == 'notes') {
|
||||
$variables['title'] = 'Notes — '.$basetitle;
|
||||
}
|
||||
|
||||
// If we are dealing with a notes post
|
||||
if ($match['name'] == 'notes_post') {
|
||||
// If we are dealing with a post (old format)
|
||||
if (($match['name'] == 'blog_post') || ($match['name'] == 'notes_post')) {
|
||||
header('Location: '.$_SERVER['SERVER_NAME'].$match['params']['slug']);
|
||||
}
|
||||
|
||||
// If we are dealing with a post
|
||||
if ($match['name'] == 'post') {
|
||||
$variables['params']['slug'] = $match['params']['slug'];
|
||||
$variables['post'] = getNotes($variables['params']);
|
||||
$variables['post'] = $variables['post'][0];
|
||||
$variables['title'] = htmlspecialchars_decode(str_replace('·','·',$variables['post']['title'])).' — '.$basetitle;
|
||||
$variables['post'] = getBlogPosts($variables['params']);
|
||||
if (count($variables['post']) == 0) {
|
||||
$variables['post'] = getNotes($variables['params']);
|
||||
}
|
||||
if (count($variables['post']) > 0) {
|
||||
$variables['post'] = $variables['post'][0];
|
||||
$variables['title'] = htmlspecialchars_decode(str_replace('·','·',$variables['post']['title'])).' — '.$basetitle;
|
||||
} else {
|
||||
$match['name'] = '404';
|
||||
}
|
||||
}
|
||||
|
||||
// If we are dealing with the projects
|
||||
@ -238,6 +251,10 @@ if ($environment === 'production') {
|
||||
\Phug\Optimizer::call('displayFile', ['notes_post', $variables], $options);
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
\Phug\Optimizer::call('displayFile', ['post', $variables], $options);
|
||||
break;
|
||||
|
||||
case 'projects':
|
||||
\Phug\Optimizer::call('displayFile', ['projects', $variables], $options);
|
||||
break;
|
||||
@ -330,6 +347,10 @@ if(is_array($match) && is_callable($match['target'])) {
|
||||
Phug::displayFile('notes_post', $variables, $options);
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
Phug::displayFile('post', $variables, $options);
|
||||
break;
|
||||
|
||||
case 'projects':
|
||||
Phug::displayFile('projects', $variables, $options);
|
||||
break;
|
||||
|
||||
55
views/post.pug
Normal file
55
views/post.pug
Normal file
@ -0,0 +1,55 @@
|
||||
extends layout
|
||||
|
||||
mixin webmention($item)
|
||||
p
|
||||
if (array_key_exists('title', $item))
|
||||
a(href="{$item['source']}") !{$item['title']}
|
||||
else
|
||||
a(href="{$item['source']}") !{$item['source']}
|
||||
if (array_key_exists('author_name', $item))
|
||||
| by !{$item['author_name']}
|
||||
if (array_key_exists('date', $item))
|
||||
| on !{$item['date']}
|
||||
if (array_key_exists('time', $item))
|
||||
| at !{$item['time']} UTC
|
||||
|
||||
mixin discussionLink($item)
|
||||
p
|
||||
a(href="{$item}") !{$item}
|
||||
|
||||
block content
|
||||
header
|
||||
nav
|
||||
a(href="/about") about me
|
||||
| >
|
||||
if ($post["type"] == "blog")
|
||||
a(href="/") blog
|
||||
if ($post["type"] == "note")
|
||||
a(href="notes") notes
|
||||
| > !{$post['slug']}
|
||||
|
||||
main
|
||||
article.longform.h-entry
|
||||
h1.p-name !{$post['title']}
|
||||
p.longform__header
|
||||
| Posted on
|
||||
a(href="{$post['url']}" datetime="{$post['date']}").u-url.dt-published !{$post['date_formatted']}
|
||||
| by
|
||||
a(href="/" rel="author").p-author.h-card !{$post['author']}
|
||||
|
||||
.longform__content.e-content
|
||||
| !{$post['content']}
|
||||
|
||||
if (array_key_exists('discussion', $post))
|
||||
.discussion.subsection
|
||||
h2 Join the discussion
|
||||
each $item in $post["discussion"]
|
||||
+discussionLink($item)
|
||||
|
||||
.webmentions.subsection
|
||||
h2 Webmentions
|
||||
if ($post['hasWebmentions'])
|
||||
each $item in $post["webmentions"]
|
||||
+webmention($item)
|
||||
else
|
||||
p This post has not been mentioned yet.
|
||||
Loading…
x
Reference in New Issue
Block a user