fix double quote in frontmatter possibility

This commit is contained in:
Wouter Groeneveld 2021-03-18 17:14:01 +01:00
parent 7b10426429
commit e463ac94e8
4 changed files with 115 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "jam-my-stack",
"version": "1.0.12",
"version": "1.0.13",
"repository": {
"url": "https://github.com/wgroeneveld/jam-my-stack",
"type": "git"

View File

@ -35,6 +35,8 @@ function convertAtomItemToMd(item, notesdir) {
writeFileSync(`${path}/${item.hash}.md`, mddata, 'utf-8')
}
const escQuotes = str => str.replace(/\"/g, "\\\"")
function trimIfNeeded(title, count, prefix) {
if(title.length > count) {
return prefix + title.substring(0, count) + "..."
@ -77,6 +79,7 @@ async function parseMastoFeed(options) {
const day = date.format("DD")
// format: <thr:in-reply-to ref='https://social.linux.pizza/users/StampedingLonghorn/statuses/105821099684887793' href='https://social.linux.pizza/users/StampedingLonghorn/statuses/105821099684887793'/>
const context = item['thr:in-reply-to'] ? item['thr:in-reply-to']['@_ref'] : ""
const title = escQuotes(ent.decode(ent.decode(item.title)))
const media = item.link?.filter(l =>
l['@_rel'] === 'enclosure' &&
@ -84,10 +87,10 @@ async function parseMastoFeed(options) {
// WHY double decode? &#34; = &amp;#34; - first decode '&', then the other char.'
return {
title: trimIfNeeded(ent.decode(ent.decode(item.title)), titleCount, titlePrefix), // summary (cut-off) of content
title: trimIfNeeded(title, titleCount, titlePrefix), // summary (cut-off) of content
content: ent.decode(ent.decode(item.content['#text'])), // format: &lt;span class=&quot;h-card....
url: item.id, // format: https://chat.brainbaking.com/objects/0707fd54-185d-4ee7-9204-be370d57663c
context,
url: escQuotes(item.id), // format: https://chat.brainbaking.com/objects/0707fd54-185d-4ee7-9204-be370d57663c
context: escQuotes(context),
id: stripBeforeLastSlash(item.id),
media,
hash: `${day}h${date.format("HH")}m${date.format("mm")}s${date.format("ss")}`,

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed
xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xmlns:activity="http://activitystrea.ms/spec/1.0/"
xmlns:poco="http://portablecontacts.net/spec/1.0"
xmlns:ostatus="http://ostatus.org/schema/1.0">
<id>https://chat.brainbaking.com/users/wouter/feed.atom</id>
<title>wouter's timeline</title>
<updated>2021-03-02T16:18:46</updated>
<logo>https://chat.brainbaking.com/media/f39bcd85-5098-45e2-b395-e274b712d512/headshot_2020.jpg</logo>
<link rel="self" href="https://chat.brainbaking.com/users/wouter/feed.atom" type="application/atom+xml"/>
<author>
<id>https://chat.brainbaking.com/users/wouter</id>
<activity:object>http://activitystrea.ms/schema/1.0/person</activity:object>
<uri>https://chat.brainbaking.com/users/wouter</uri>
<poco:preferredUsername>wouter</poco:preferredUsername>
<poco:displayName>Wouter Groeneveld</poco:displayName>
<poco:note>Level 35 Brain Baker. Loving the smell of freshly baked thoughts (and bread) in the morning 🍞. Sometimes convincing others to bake their brain (and bread) too 🧠. </poco:note>
<summary>Level 35 Brain Baker. Loving the smell of freshly baked thoughts (and bread) in the morning 🍞. Sometimes convincing others to bake their brain (and bread) too 🧠. </summary>
<name>wouter</name>
<link rel="avatar" href="https://chat.brainbaking.com/media/f39bcd85-5098-45e2-b395-e274b712d512/headshot_2020.jpg"/>
<link rel="header" href="https://chat.brainbaking.com/media/3399cd78-4fd4-40ab-a174-c7805576a826/boekcover2.jpg"/>
<ap_enabled>true</ap_enabled>
</author>
<link rel="next" href="https://chat.brainbaking.com/users/wouter/feed.atom?max_id=A4fIjNa6N1OJmaSMAS" type="application/atom+xml"/>
<entry>
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<id>https://chat.brainbaking.com/objects/2e58289c-f5f0-415c-b2e1-62c74662aa16</id>
<title>"wow this sucks" with quotes</title>
<content type="html">"hi there" with quotes content</content>
<published>2021-03-02T16:18:46.658056Z</published>
<updated>2021-03-02T16:18:46.658056Z</updated>
<ostatus:conversation ref="tag:mastodon.social,2021-03-01:objectId=224637732:objectType=Conversation">
tag:mastodon.social,2021-03-01:objectId=224637732:objectType=Conversation
</ostatus:conversation>
<link href="tag:mastodon.social,2021-03-01:objectId=224637732:objectType=Conversation" rel="ostatus:conversation"/>
<summary></summary>
<link type="application/atom+xml" href='https://chat.brainbaking.com/objects/2e58289c-f5f0-415c-b2e1-62c74662aa16' rel="self"/>
<link type="text/html" href='https://chat.brainbaking.com/objects/2e58289c-f5f0-415c-b2e1-62c74662aa16' rel="alternate"/>
<thr:in-reply-to ref='https://social.linux.pizza/users/StampedingLonghorn/statuses/105821099684887793' href='https://social.linux.pizza/users/StampedingLonghorn/statuses/105821099684887793'/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://social.linux.pizza/users/StampedingLonghorn"/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://chat.brainbaking.com/users/wouter"/>
</entry>
</feed>

View File

@ -29,6 +29,19 @@ describe("mastodon feed parser tests", () => {
expect(actualMd).toMatchSnapshot()
})
test("parse prepends double quotes with backlash to escape in frontmatter", async () => {
await parseMastoFeed({
url: "masto-feed-quote",
notesdir: dumpdir,
utcOffset: 0
})
const actualMd = await fsp.readFile(`${dumpdir}/2021/03/02h16m18s46.md`)
const md = frontMatterParser.parseSync(actualMd.toString())
expect(md.data.title).toBe("\"wow this sucks\" with quotes")
})
test("parse trims title according to config and adds three dots", async () => {
await parseMastoFeed({
url: "masto-feed-sample",