diff --git a/functions.php b/functions.php index 229d418..89b7280 100644 --- a/functions.php +++ b/functions.php @@ -58,6 +58,11 @@ function getBlogPosts($params) { continue; } + if (isset($params['slug'])) { + $post["webmentions"] = getWebmentions($post["url"]); + $post["hasWebmentions"] = count($post["webmentions"]) > 0; + } + $posts[] = $post; } @@ -104,6 +109,11 @@ function getNotes($params) { continue; } + if (isset($params['slug'])) { + $post["webmentions"] = getWebmentions($post["url"]); + $post["hasWebmentions"] = count($post["webmentions"]) > 0; + } + $posts[] = $post; } @@ -150,12 +160,29 @@ function getProjects($params) { continue; } + if (isset($params['slug'])) { + $project["webmentions"] = getWebmentions($post["url"]); + $project["hasWebmentions"] = count($project["webmentions"]) > 0; + } + $projects[] = $project; } return $projects; } +function getWebmentions($target) { + $data json_decode(file_get_contents("https://webm.yarmo.eu/get?target=$target"), true); + + foreach ($data as $id => $entry) { + $time = strtotime($entry["created_at"]); + $data[$id]["date"] = date("Y-m-d",$time); + $data[$id]["time"] = date("H:i:s",$time); + } + + return $data; +} + function getFOSS() { return Yaml::parseFile('content/foss/foss.yaml'); } diff --git a/static/style.css b/static/style.css index ee1f54f..cccc6a9 100644 --- a/static/style.css +++ b/static/style.css @@ -307,6 +307,10 @@ table.music th:nth-child(3) { font-style: normal; font-size: 90%; } +.webmentions { + margin: 64px 0 0; + border-top: 3px dashed rgba(0,0,0,0.5); +} /* Lists */ .list { diff --git a/views/blog_post.pug b/views/blog_post.pug index 336a8aa..76235e7 100644 --- a/views/blog_post.pug +++ b/views/blog_post.pug @@ -1,5 +1,10 @@ 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 @@ -19,3 +24,11 @@ block content .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. diff --git a/views/notes_post.pug b/views/notes_post.pug index 51dada0..4c008c8 100644 --- a/views/notes_post.pug +++ b/views/notes_post.pug @@ -1,5 +1,10 @@ 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 @@ -19,3 +24,11 @@ block content .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. diff --git a/views/projects_details.pug b/views/projects_details.pug index 4256176..c55810c 100644 --- a/views/projects_details.pug +++ b/views/projects_details.pug @@ -1,5 +1,10 @@ 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 @@ -17,3 +22,11 @@ block content p.longform__header .longform__content | !{$project['content']} + + .webmentions + h2 Webmentions + if ($project['hasWebmentions']) + each $item in $project["webmentions"] + +webmention($item) + else + p This project has not been mentioned yet.