') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - 5k18a/statamic-comments-section: Entry-based blog comments for Statamic 6 — moderation, threaded replies, global kill switch. MIT. · GitHub
Skip to content

Repository files navigation

Statamic Comments Section

Latest VersionLicense: MITStatamic 6

A self-contained Statamic addon that adds entry-based blog comments with moderation and a global on/off kill switch. Comments are stored as regular Statamic entries — Git-friendly, queryable, and fully under your control. No external service, no database table, no third party.

Package name on Packagist/Composer: skalisty/comments. Source repository: 5k18a/statamic-comments-section.

Features

  • Entry-based storage — every comment is an entry in a comments collection (flat files, versionable).
  • Moderation — new comments are created as drafts and only appear once published (require_moderation).
  • Threaded replies — each comment records its parent, so replies nest under the comment they answer.
  • Global kill switch — enable/disable the whole system from a Global Set; when off, nothing renders on the front end and the submission listener is inert.
  • Static-cache aware — the related blog entry's static cache is invalidated automatically whenever a comment is created, published, or deleted.
  • Deterministic avatarsavatar_initial and avatar_color modifiers generate initial-based avatars with a stable per-author color (no uploads, no Gravatar dependency).
  • Moderation panel (Control Panel) — a Tools › Comments utility (native Statamic UI kit, Inertia/Vue) to browse comments grouped per blog entry across all locales, with a lazy per-blog listing, full-comment modal, and inline publish / unpublish / cascade-delete. Available even when front-end comments are disabled.
  • Migration command — convert existing form submissions into comment entries.

Requirements

  • PHP 8.4+
  • Statamic 6

Installation

composer require skalisty/comments

Until the package is listed on Packagist, install straight from the repository by adding it to your project composer.json:

{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/5k18a/statamic-comments-section"
}
]
}

then run composer require skalisty/comments:dev-main.

Publish the config file (optional):

php artisan vendor:publish --tag=comments-config

Configuration

config/comments.php:

return [
'enabled' => false, // master switch (fallback for the Global Set)'require_moderation' => true, // new comments start as drafts'per_page' => 5, // comments per page on the front end'site' => 'pl', // site handle the comments collection lives on'settings' => [
'global_handle' => 'comments', // Global Set that overrides these values in the CP
],
];

The comments Global Set overrides enabled, require_moderation and per_page at runtime, so editors can toggle the system from the Control Panel without a deploy. Config values are the fallback.

Setup

The addon expects:

  1. A comments collection (site handle matching config('comments.site')) using the bundled comment blueprint fields: title, author_name, author_email, message, commented_at, blog_entry_id, parent_comment, source_submission_id.
  2. A form (default handle blog_comment) whose submissions are converted into comment entries. Hidden fields blog_id (the blog entry id) and parent_id (optional parent comment id) drive the association and threading.
    • Recommended: set store: false on this form. Statamic still dispatches SubmissionCreated even when storing is disabled, so the addon's listener creates the comment entry as usual — but no redundant form submission is persisted on disk (otherwise every comment is saved twice: once under Forms › Blog Comments and once as a comment entry). reCAPTCHA/honeypot validation is unaffected; it runs before the submission is created.

Usage

Render the comments block on a blog entry template:

{{ comments:section }}

Parameters:

ParameterDefaultDescription
blog_entry_idcurrent entry idWhich blog entry the comments belong to.
variantthreeLayout variant of the bundled view.
per_pageconfig per_pageComments per page.
comments_siteconfig siteSite handle the comments collection lives on.

When the system is disabled (Global Set or config), the tag renders an empty string.

Avatar modifiers

<spanstyle="background: {{ author_name | avatar_color }}">
{{ author_name|avatar_initial }}
</span>
  • avatar_initial — first letter of the author's name (uppercase), ? fallback.
  • avatar_color — deterministic hsl(...) background derived from the name (same author → same color).

Migration command

Convert existing blog_comment submissions into comment entries:

php please comments:migrate # create drafts
php please comments:migrate --publish # publish immediately
php please comments:migrate --dry-run # preview without writing

Roadmap

  • Packagist listing for a plain composer require skalisty/comments.
  • Optional email notifications on new comments.

License

MIT — free to use, modify and distribute, for everyone.

Credits

Created and maintained by Marcin Skibicki (5k18a).

About

Entry-based blog comments for Statamic 6 — moderation, threaded replies, global kill switch. MIT.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages