From 12219c480fb26a534cd65aeaac9f51557a8dbc3e Mon Sep 17 00:00:00 2001 From: Benji Encalada Mora Date: Mon, 20 Jan 2020 01:26:45 -0600 Subject: [PATCH] use JSON.stringify for content --- .eleventy.js | 10 ++++------ feed/json.njk | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 2f610c6..77c9143 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -20,13 +20,11 @@ module.exports = function(eleventyConfig) { }); // Content for jsonfeed - eleventyConfig.addFilter('jsonContent', content => { - if (content) { - content = content.replace(/(\r\n|\n|\r)/gm, ""); - content = content.replace(/\t/g, "\\t"); - content = content.replace(/"/g, '\\"'); + eleventyConfig.addFilter('jsonStringify', content => { + if (!content) { + content = ""; } - return content; + return JSON.stringify(content); }); // Get the first `n` elements of a collection. diff --git a/feed/json.njk b/feed/json.njk index 85200d0..97e0841 100644 --- a/feed/json.njk +++ b/feed/json.njk @@ -19,7 +19,7 @@ eleventyExcludeFromCollections: true "id": "{{ absolutePostUrl }}", "url": "{{ absolutePostUrl }}", "title": "{{ post.data.title }}", - "content_html": "{{ post.templateContent | jsonContent | safe }}", + "content_html": {{ post.templateContent | jsonStringify | safe }}, "date_published": "{{ post.date | rssDate }}", "tags": [ {%- for c in post.data.category %}