mirror of
https://github.com/tcsenpai/obsidiangarden_netlify.git
synced 2025-06-05 12:25:20 +00:00
Escape "\" in tags, as they are invalid json
This commit is contained in:
parent
6c8f6a5ebe
commit
514f1be060
@ -289,6 +289,15 @@ module.exports = function (eleventyConfig) {
|
||||
return JSON.stringify(variable) || '""';
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter('validJson', function (variable) {
|
||||
if(Array.isArray((variable))){
|
||||
return variable.map(x=>x.replaceAll("\\", "\\\\")).join(",");
|
||||
}else if(typeof(variable) === 'string'){
|
||||
return variable.replaceAll("\\", "\\\\");
|
||||
}
|
||||
return variable;
|
||||
});
|
||||
|
||||
return {
|
||||
dir: {
|
||||
input: "src/site",
|
||||
|
@ -9,6 +9,6 @@ eleventyExcludeFromCollections: true
|
||||
"date":"{{ post.date }}",
|
||||
"url":"{{ post.url }}",
|
||||
"content": {{ post.templateContent | striptags(true) | link | jsonify | safe }},
|
||||
"tags": [{{post.templateContent | link | searchableTags | safe }} {% if post.data.tags %}{% for tag in post.data.tags %}"{{tag}}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %}]
|
||||
"tags": [{{post.templateContent | link | searchableTags | safe }} {% if post.data.tags %}{% for tag in post.data.tags %}"{{tag|validJson}}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %}]
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}]
|
||||
|
Loading…
x
Reference in New Issue
Block a user