Compare commits

...

3 Commits

Author SHA1 Message Date
Yarmo Mackenbach
c3e9ddae40 Add reply
All checks were successful
continuous-integration/drone/push Build is passing
2020-06-23 18:15:00 +02:00
Yarmo Mackenbach
e19bafa42a Add support for replies 2020-06-23 18:14:47 +02:00
Yarmo Mackenbach
9fd1f69cf5 Remove obsolete templates 2020-06-23 17:58:34 +02:00
6 changed files with 85 additions and 110 deletions

View File

@ -0,0 +1,11 @@
---
title: Webmention, ActivityPub Support!
reply-url: https://degruchy.org/2020/06/22/webmention-activitypub-support/
reply-title: Webmention, ActivityPub Support!
author: Yarmo Mackenbach
slug: reply-01-degruchy-activitypub
date: "2020-06-23 18:09:13"
published: true
---
Great to hear about the progress. I might implement ActivityPub later, but I recently also got webmentions working. I did check your @nathan@degruchy.org fediverse account, no new content just yet but I'll keep checking. Have a good one!

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;
if (isset($params['slug'])) {
$item["webmentions"] = getWebmentions($item["url"]);
$item["hasWebmentions"] = count($item["webmentions"]) > 0;
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));
$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;
}

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;

View File

@ -1,52 +0,0 @@
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
| >
a(href="/") blog
| > !{$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 ($post['discussion'])
.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.

View File

@ -1,34 +0,0 @@
extends layout
mixin webmention($item)
p
a(href="{$item['source']}") !{$item['title']}
| by !{$item['author_name']} on !{$item['date']} at !{$item['time']}
block content
header
nav
a(href="/about") about me
| >
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']}
.webmentions
h2 Webmentions
if ($post['hasWebmentions'])
each $item in $post["webmentions"]
+webmention($item)
else
p This post has not been mentioned yet.

23
views/reply.pug Normal file
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']}