From 4dda1e0a9cd81e933e3163566cc9818bf16d25e7 Mon Sep 17 00:00:00 2001 From: "max.mehl" Date: Wed, 16 Oct 2019 19:46:39 +0200 Subject: [PATCH] further improvements, make more portable --- config.toml | 5 +++++ .../layouts/partials/comments.html | 5 +++-- .../static/comments/getcomments.js | 2 +- .../static/comments/getcomments.php | 14 +++++++++++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/config.toml b/config.toml index 9cbbd3d..737b148 100755 --- a/config.toml +++ b/config.toml @@ -33,6 +33,11 @@ extensions = [ "hardLineBreak" ] Mastodon = "mastodon.social/@mxmehl" Diaspora = "diasp.eu/u/mxmehl" +[params.mastodoncomments] + user = "https://mastodon.social/users/mxmehl" + regex = '/\/?blog\/\d\d\d\d\/.+$/' + contact = "/contact/" + ## Main Menu [[menu.main]] name = "start" diff --git a/themes/hugo-mastodon-comments/layouts/partials/comments.html b/themes/hugo-mastodon-comments/layouts/partials/comments.html index 8d2ad9f..997856c 100644 --- a/themes/hugo-mastodon-comments/layouts/partials/comments.html +++ b/themes/hugo-mastodon-comments/layouts/partials/comments.html @@ -7,8 +7,9 @@
- - + + + diff --git a/themes/hugo-mastodon-comments/static/comments/getcomments.js b/themes/hugo-mastodon-comments/static/comments/getcomments.js index 8df5fe7..9f9c743 100644 --- a/themes/hugo-mastodon-comments/static/comments/getcomments.js +++ b/themes/hugo-mastodon-comments/static/comments/getcomments.js @@ -11,7 +11,7 @@ $(document).ready(function() { url: "/comments/getcomments.php", type: "get", data: { - search : RelPermalink + search : "https://fsfe.org/news/2019/news-20190326-01.html" }, success: function(data) { var stats = data.stats; diff --git a/themes/hugo-mastodon-comments/static/comments/getcomments.php b/themes/hugo-mastodon-comments/static/comments/getcomments.php index 0eca6dc..e8191f4 100644 --- a/themes/hugo-mastodon-comments/static/comments/getcomments.php +++ b/themes/hugo-mastodon-comments/static/comments/getcomments.php @@ -8,6 +8,12 @@ $search = isset($_GET['search']) ? $_GET['search'] : ''; /* cache files */ $dbt = "cache-toots.json"; +/* Exit if search empty */ +if (empty($search)) { + out("No proper search given"); + die(); +} + /* MISC FUNCTIONS */ function out($data) { error_log("[getcomments.php] " . print_r($data, TRUE)); @@ -47,6 +53,7 @@ if (!empty($toots['0']['id'])) { } else { /* if cached toots do not exist, start from oldest toot */ $min_id = "0"; + $min_id_cached = "0"; } @@ -92,11 +99,12 @@ if ($min_id !== $min_id_cached) { /* check if URL from $search exists in $toots */ // if multiple exist, take the oldest one (highest array position) $id = array_keys(array_column($toots, 'url'), strtolower($search)); +if (empty($id)) { + out("Blog URL \"$search\" has not been found"); + die(); +} $id = $toots[end($id)]['id']; -// TODO: graceful exit if no toot exists - -$id = "102955148581768112"; // TODO test /* Extract comments and stats from toot */ $result = ['comments' => [], 'stats' => ['reblogs' => 0, 'favs' => 0, 'replies' => 0, 'url' => '', 'root' => 0]];