use JSON.stringify for content

This commit is contained in:
Benji Encalada Mora 2020-01-20 01:26:45 -06:00
parent fb7383c3ed
commit 12219c480f
No known key found for this signature in database
GPG Key ID: DBEBBE9A2EB76EEB
2 changed files with 5 additions and 7 deletions

View File

@ -20,13 +20,11 @@ module.exports = function(eleventyConfig) {
}); });
// Content for jsonfeed // Content for jsonfeed
eleventyConfig.addFilter('jsonContent', content => { eleventyConfig.addFilter('jsonStringify', content => {
if (content) { if (!content) {
content = content.replace(/(\r\n|\n|\r)/gm, ""); content = "";
content = content.replace(/\t/g, "\\t");
content = content.replace(/"/g, '\\"');
} }
return content; return JSON.stringify(content);
}); });
// Get the first `n` elements of a collection. // Get the first `n` elements of a collection.

View File

@ -19,7 +19,7 @@ eleventyExcludeFromCollections: true
"id": "{{ absolutePostUrl }}", "id": "{{ absolutePostUrl }}",
"url": "{{ absolutePostUrl }}", "url": "{{ absolutePostUrl }}",
"title": "{{ post.data.title }}", "title": "{{ post.data.title }}",
"content_html": "{{ post.templateContent | jsonContent | safe }}", "content_html": {{ post.templateContent | jsonStringify | safe }},
"date_published": "{{ post.date | rssDate }}", "date_published": "{{ post.date | rssDate }}",
"tags": [ "tags": [
{%- for c in post.data.category %} {%- for c in post.data.category %}