diff --git a/CHANGES.rst b/CHANGES.rst index a85dc2e7e..f98982f3e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,16 @@ Changelog for Isso ================== +%(version)s (%(date)s) +-------------------- + +New Features +^^^^^^^^^^^^ + +- Add option to show/hide website field in comment form (`#1111`_, pkvach) + +.. _#1111: https://github.com/isso-comments/isso/pull/1111 + 0.14.0 (2026-03-26) -------------------- diff --git a/docs/docs/reference/server-config.rst b/docs/docs/reference/server-config.rst index 7884cea40..be16cdb6b 100644 --- a/docs/docs/reference/server-config.rst +++ b/docs/docs/reference/server-config.rst @@ -348,6 +348,7 @@ for IPv4, ``/48`` for IPv6). reply-to-self = false require-author = false require-email = false + website-field = true enabled Enable guard, recommended in production. Not useful for debugging @@ -385,6 +386,14 @@ require-email Default: ``false`` +website-field + Whether to show the website input field in the comment form. Set to + ``false`` to hide the website field entirely (no CSS hacks needed). + + Default: ``true`` + + .. versionadded:: 0.14.1 + .. _configure-markup: Markup diff --git a/isso/isso.cfg b/isso/isso.cfg index 9c927ce4b..85e7eb2de 100644 --- a/isso/isso.cfg +++ b/isso/isso.cfg @@ -195,6 +195,10 @@ require-author = false # done on the provided address). Do not forget to configure the client. require-email = false +# Whether to show the website input field in the comment form. +# Set to false to hide the website field entirely. +website-field = true + [markup] # Customize markup and sanitized HTML. Currently, only Markdown (via mistune or misaka) is diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index c4b6a33fb..5471c3945 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -17,7 +17,7 @@ var Postbox = function(parent) { el = $.htmlify(template.render("postbox", { "author": JSON.parse(localStorage.getItem("isso-author")), "email": JSON.parse(localStorage.getItem("isso-email")), - "website": JSON.parse(localStorage.getItem("isso-website")), + "website": config["website-field"] !== false ? JSON.parse(localStorage.getItem("isso-website")) : null, "preview": '' })); @@ -103,7 +103,8 @@ var Postbox = function(parent) { var author = $("[name=author]", el).value || null, email = $("[name=email]", el).value || null, - website = $("[name=website]", el).value || null; + websiteEl = config["website-field"] !== false ? $('[name=website]', el) : null, + website = websiteEl ? websiteEl.value || null : null; try { localStorage.setItem("isso-author", JSON.stringify(author)); diff --git a/isso/js/app/templates/postbox.js b/isso/js/app/templates/postbox.js index 5897d5692..5428971c1 100644 --- a/isso/js/app/templates/postbox.js +++ b/isso/js/app/templates/postbox.js @@ -28,10 +28,10 @@ var html = function (globals) { + "" + "" + "
" - + "" + + (conf["website-field"] !== false ? "
" + "" + "" - + "
" + + "" : "") + "" + "" + "
" diff --git a/isso/js/tests/unit/postbox-website-field.test.js b/isso/js/tests/unit/postbox-website-field.test.js new file mode 100644 index 000000000..060ba4087 --- /dev/null +++ b/isso/js/tests/unit/postbox-website-field.test.js @@ -0,0 +1,75 @@ +/** + * @jest-environment jsdom + */ + +/* Keep the above exactly as-is! + * https://jestjs.io/docs/configuration#testenvironment-string + * https://jestjs.io/docs/configuration#testenvironmentoptions-object + */ + +"use strict"; + +beforeEach(() => { + jest.resetModules(); + document.body.innerHTML = ''; +}); + +test('Website field hidden when website-field=false', () => { + document.body.innerHTML = + '' + + ''; + + const isso = require("app/isso"); + const $ = require("app/dom"); + + const config = Object.assign({}, require("app/config"), {'website-field': false}); + + const i18n = require("app/i18n"); + const svg = require("app/svg"); + const template = require("app/template"); + + template.set("conf", config); + template.set("i18n", i18n.translate); + template.set("pluralize", i18n.pluralize); + template.set("svg", svg); + + const isso_thread = $('#isso-thread'); + isso_thread.append(''); + isso_thread.append(new isso.Postbox(null)); + + // Website input should not be present + expect(document.querySelector('#isso-postbox-website')).toBeNull(); + expect(document.querySelector('[name=website]')).toBeNull(); + + // Author and email fields should still be present + expect(document.querySelector('#isso-postbox-author')).not.toBeNull(); + expect(document.querySelector('#isso-postbox-email')).not.toBeNull(); +}); + +test('Website field shown when website-field=true (default)', () => { + document.body.innerHTML = + '' + + ''; + + const isso = require("app/isso"); + const $ = require("app/dom"); + + const config = Object.assign({}, require("app/config"), {'website-field': true}); + + const i18n = require("app/i18n"); + const svg = require("app/svg"); + const template = require("app/template"); + + template.set("conf", config); + template.set("i18n", i18n.translate); + template.set("pluralize", i18n.pluralize); + template.set("svg", svg); + + const isso_thread = $('#isso-thread'); + isso_thread.append(''); + isso_thread.append(new isso.Postbox(null)); + + // Website input should be present + expect(document.querySelector('#isso-postbox-website')).not.toBeNull(); + expect(document.querySelector('[name=website]')).not.toBeNull(); +}); diff --git a/isso/views/comments.py b/isso/views/comments.py index d5a035c4d..3864ed865 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -199,6 +199,10 @@ def __init__(self, isso, hasher): self.public_conf["reply-to-self"] = isso.conf.getboolean("guard", "reply-to-self") self.public_conf["require-email"] = isso.conf.getboolean("guard", "require-email") self.public_conf["require-author"] = isso.conf.getboolean("guard", "require-author") + try: + self.public_conf["website-field"] = isso.conf.getboolean("guard", "website-field") + except NoOptionError: + self.public_conf["website-field"] = True self.public_conf["reply-notifications"] = isso.conf.getboolean("general", "reply-notifications") self.public_conf["gravatar"] = isso.conf.getboolean("general", "gravatar")