message: Automatically update the sample letter blog posts
diff: @@ -8,8 +8,8 @@ const renderCarbone = util.promisify(carbone.render).bind(carbone);
  const PDFDocument = require('pdfkit');
  const { templatify, mm2pt } = require('./util');
  -// This script generates the sample letters in the various formats from our request templates, which was previously done
  -// manually (and a source of great pain and suffering).
  +// This script generates the sample letters in the various formats from our request templates and update the
  +// corresponding blog post, which was previously done manually (and a source of great pain and suffering).
  // It would be great to move the template translations into Weblate, have that be the single source of truth for our
  // templates and then have everything else be generated by this script. Unfortunately, that is not possible right now as
  @@ -212,6 +212,37 @@ const out_dir = path.join(__dirname, '..', '..', 'static', 'downloads');
  pdf.pipe(fs.createWriteStream(path.join(out_dir, `${data.filename}.pdf`)));
  pdf.end();
  +
  + // Build TXT.
  + const txt_text = `${'='.repeat(data.subject.length)}
  +${data.subject}
  +${'='.repeat(data.subject.length)}
  +
  +${data.explanation}
  +
  +---
  +
  +${text.join('\n\n')}
  +${data.your_name}`;
  + fs.writeFileSync(path.join(out_dir, `${data.filename}.txt`), txt_text);
  +
  + // Update blog post.
  + const post_text = [...text, data.your_name]
  + .map((l) => l.replace(/{(.+)}/, '<span class="blog-letter-fill-in">$1</span>').replace(/\n/g, '<br>\n'))
  + .map((l) => `<p>${l}</p>`)
  + .join('\n\n');
  + const post_slug = `sample-letter-gdpr-${
  + type === 'objection' ? 'direct-marketing-objection' : `${type}-request`
  + }`;
  + const post_path = path.join(__dirname, '..', '..', 'content', lang, 'blog', post_slug, 'index.md');
  + const old_text = fs.readFileSync(post_path).toString();
  + const new_text = old_text.replace(
  + /<div class="blog-letter">[\S\s]+?<\/div>/,
  + `<div class="blog-letter">
  +${post_text}
  +</div>`
  + );
  + fs.writeFileSync(post_path, new_text);
  }
  }
  })();
  