eduardoboucas/staticman

Allow for bypassing Akismet spam-checking (when testing)

hispanic opened this issue · 0 comments

In Staticman, Akismet spam-checking is turned on/off via the akismet.enabled property in the site config. When running Staticman in a testing, staging, or production environment, it would help facilitate testing if there was a per-request way to bypass Akismet spam-checking. Pumping too many test comments through Akismet (the free plan that does not allow for any review) can result in Akismet flagging test data as spam.

Suggested configuration addition (to the JSON app config):

    bypassValue: {
      doc: 'Value to pass in as comment author, author email, author URL, or content in order to bypass Akismet spam-checking. Intended to be used for testing in lieu of disabling Akismet via the site config.',
      format: String,
      default: null,
      env: 'AKISMET_BYPASS_VALUE'
    }

Demonstration code:

      const akismetData = {
        user_ip: this.ip,
        user_agent: this.userAgent,
        comment_type: this.siteConfig.get('akismet.type'),
        comment_author: fields[this.siteConfig.get('akismet.author')],
        comment_author_email: fields[this.siteConfig.get('akismet.authorEmail')],
        comment_author_url: fields[this.siteConfig.get('akismet.authorUrl')],
        comment_content: fields[this.siteConfig.get('akismet.content')]
      }

      const akismetBypassValue = config.get('akismet.bypassValue')
      if (akismetBypassValue !== null && akismetBypassValue !== '' && typeof akismetBypassValue !== 'undefined') {
        if (akismetData.comment_author === akismetBypassValue ||
          akismetData.comment_author_email === akismetBypassValue ||
          akismetData.comment_author_url === akismetBypassValue ||
          akismetData.comment_content === akismetBypassValue) {
          return resolve(fields)
        }
      }

In English, this means that if the author name, author email, author url, or comment content are set to the bypass value, Akismet will not be invoked for that submission. Obviously, you'd want to keep this bypass value secret.