Browse Source

Add support for replies

master
Yarmo Mackenbach 1 week ago
parent
commit
e19bafa42a
3 changed files with 74 additions and 24 deletions
  1. +35
    -22
      functions.php
  2. +16
    -2
      index.php
  3. +23
    -0
      views/reply.pug

+ 35
- 22
functions.php View File

@ -37,6 +37,11 @@ function getProjects($params) {
return $projects;
}
function getReplies($params) {
$projects = scandirRec('content/replies/', 'replies', $params);
return $projects;
}
function getWebmentions($target) {
$data = json_decode(file_get_contents("https://webm.yarmo.eu/get?target=$target"), true);
@ -142,14 +147,6 @@ function scandirRec($path, $category, $params) {
if (!$item['published'] && !(isset($params['slug']) && $item['slug'] == $params['slug'])) {
return;
}
if (isset($params['slug']) && $item['slug'] != $params['slug']) {
return;
}
if (isset($params['slug'])) {
$item["webmentions"] = getWebmentions($item["url"]);
$item["hasWebmentions"] = count($item["webmentions"]) > 0;
}
break;
case 'notes':
@ -172,14 +169,6 @@ function scandirRec($path, $category, $params) {
if (!$item['published'] && !(isset($params['slug']) && $item['slug'] == $params['slug'])) {
return;
}
if (isset($params['slug']) && $item['slug'] != $params['slug']) {
return;
}
if (isset($params['slug'])) {
$item["webmentions"] = getWebmentions($item["url"]);
$item["hasWebmentions"] = count($item["webmentions"]) > 0;
}
break;
case 'projects':
@ -196,16 +185,32 @@ function scandirRec($path, $category, $params) {
$date = new DateTime($item['date']);
$item['date_formatted'] = $date->format('Y-m-d');
$item['date_rss'] = $date->format('Y-m-d');
if (!$item['listed'] && !(isset($params['slug']) && $item['slug'] == $params['slug'])) {
return;
}
if (isset($params['slug']) && $item['slug'] != $params['slug']) {
return;
}
break;
case 'replies':
$item = array(
"type" => "note",
"title" => $meta["title"],
"reply-url" => $meta["reply-url"],
"reply-title" => $meta["reply-title"],
"author" => $meta["author"],
"urlrel" => "/reply/".$meta["slug"],
"url" => "https://yarmo.eu/reply/".$meta["slug"],
"slug" => $meta["slug"],
"date" => $meta["date"],
"published" => $meta["published"],
"content" => $mp->text($content));
if (isset($params['slug'])) {
$item["webmentions"] = getWebmentions($item["url"]);
$item["hasWebmentions"] = count($item["webmentions"]) > 0;
$date = new DateTime($item['date']);
$item['date_formatted'] = $date->format('Y-m-d');
$item['date_rss'] = $date->format('Y-m-d');
if (!$item['published'] && !(isset($params['slug']) && $item['slug'] == $params['slug'])) {
return;
}
break;
@ -214,5 +219,13 @@ function scandirRec($path, $category, $params) {
break;
}
if (isset($params['slug']) && $item['slug'] != $params['slug']) {
return;
}
if (isset($params['slug'])) {
$item["webmentions"] = getWebmentions($item["url"]);
$item["hasWebmentions"] = count($item["webmentions"]) > 0;
}
return $item;
}

+ 16
- 2
index.php View File

@ -23,6 +23,7 @@ $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', '/reply/[*:slug]', function() {}, 'reply');
$router->map('GET', '/projects', function() {}, 'projects');
$router->map('GET', '/projects/[*:slug]', function() {}, 'projects_details');
$router->map('GET', '/foss', function() {}, 'foss');
@ -127,7 +128,6 @@ if (($match['name'] == 'blog_post') || ($match['name'] == 'notes_post')) {
// If we are dealing with a post
if ($match['name'] == 'post') {
$match['params']['slug'] = $match['params']['slug'];
$variables['post'] = getBlogPosts($match['params']);
if (count($variables['post']) == 0) {
$variables['post'] = getNotes($match['params']);
@ -140,6 +140,13 @@ if ($match['name'] == 'post') {
}
}
// If we are dealing with a reply
if ($match['name'] == 'reply') {
$variables['reply'] = getReplies($match['params']);
$variables['reply'] = $variables['reply'][0];
$variables['title'] = htmlspecialchars_decode(str_replace('·','·',$variables['reply']['title'])).' — '.$basetitle;
}
// If we are dealing with the projects
if ($match['name'] == 'projects') {
$variables['projects'] = getProjects($match['params']);
@ -148,7 +155,6 @@ if ($match['name'] == 'projects') {
// If we are dealing with a project's details
if ($match['name'] == 'projects_details') {
$match['params']['slug'] = $match['params']['slug'];
$variables['project'] = getProjects($match['params']);
$variables['project'] = $variables['project'][0];
$variables['title'] = htmlspecialchars_decode(str_replace('·','·',$variables['project']['title'])).' — '.$basetitle;
@ -247,6 +253,10 @@ if ($environment === 'production') {
\Phug\Optimizer::call('displayFile', ['post', $variables], $options);
break;
case 'reply':
\Phug\Optimizer::call('displayFile', ['reply', $variables], $options);
break;
case 'projects':
\Phug\Optimizer::call('displayFile', ['projects', $variables], $options);
break;
@ -343,6 +353,10 @@ if(is_array($match) && is_callable($match['target'])) {
Phug::displayFile('post', $variables, $options);
break;
case 'reply':
Phug::displayFile('reply', $variables, $options);
break;
case 'projects':
Phug::displayFile('projects', $variables, $options);
break;

+ 23
- 0
views/reply.pug View File

@ -0,0 +1,23 @@
extends layout
block content
header
nav
a(href="/about") about me
| > !{$reply['slug']}
main
article.longform.h-entry
h1.p-name !{$reply['title']}
p.longform__header
| Posted on
a(href="{$reply['url']}" datetime="{$reply['date']}").u-url.dt-published !{$reply['date_formatted']}
| by
a(href="/" rel="author").p-author.h-card !{$reply['author']}
.longform__content.e-content
| Reply to
a(href="{$reply['reply-url']}").in-reply-to !{$reply['reply-title']}
| :
br
| !{$reply['content']}

Loading…
Cancel
Save