From e49778e0ede1375fe4663cc574cd78551af1815b Mon Sep 17 00:00:00 2001 From: "max.mehl" Date: Wed, 16 Oct 2019 20:03:39 +0200 Subject: [PATCH] Improve JS and portability --- config.toml | 6 +++++- .../static/comments/getcomments.js | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/config.toml b/config.toml index 737b148..2f34e76 100755 --- a/config.toml +++ b/config.toml @@ -34,8 +34,12 @@ extensions = [ "hardLineBreak" ] Diaspora = "diasp.eu/u/mxmehl" [params.mastodoncomments] + # Link to your Mastodon profile. Please use the format https:///users/ user = "https://mastodon.social/users/mxmehl" - regex = '/\/?blog\/\d\d\d\d\/.+$/' + # A regex which defines the relative path for URLs which you want to grep comments for. + # Character classes like \d (digits) have to be escaped, so \\d + regex = '/blog/\\d\\d\\d\\d/.+$' + # Contact address or URL. Can be a relative or absolute URL, or also a mailto:// address contact = "/contact/" ## Main Menu diff --git a/themes/hugo-mastodon-comments/static/comments/getcomments.js b/themes/hugo-mastodon-comments/static/comments/getcomments.js index 9f9c743..9b31851 100644 --- a/themes/hugo-mastodon-comments/static/comments/getcomments.js +++ b/themes/hugo-mastodon-comments/static/comments/getcomments.js @@ -1,7 +1,9 @@ $(document).ready(function() { - // check if we show a blog post or not. You might have to adapt this - var isArticle = /\/?blog\/\d\d\d\d\/.+$/.test(RelPermalink); + // check if we show a blog post or not. Regex is defined in site-wide config + var patt = new RegExp(BlogRegex); + console.log(patt); + var isArticle = patt.test(RelPermalink); if (isArticle === false) { console.log("Not a blog post, no need to search for comments"); return; @@ -38,11 +40,11 @@ $(document).ready(function() { } }); if (parseInt(root) > 0) { - $("#reference").append("Join the discussion on Mastodon!"); + $("#reference").append("Join the discussion on Mastodon!"); } else { $("#comments").empty(); $("#statistics").empty(); - $("#reference").append("Comments are handled by my Mastodon account. Sadly this article wasn't published at Mastodon. Feel free to send me a mail if you want to share your thoughts regarding this topic."); + $("#reference").append("Comments are handled by my Mastodon account. Sadly this article wasn't published at Mastodon. Feel free to send me a mail if you want to share your thoughts regarding this topic."); } }