add the option ignoreReplies
This commit is contained in:
parent
e463ac94e8
commit
e577012002
|
@ -35,11 +35,12 @@ Usage example:
|
|||
})
|
||||
```
|
||||
|
||||
Default values:
|
||||
Options and their default values:
|
||||
|
||||
- `utcOffset`: `60` (= GMT+1, that's where I am!) (in **minutes**, see [day.js docs](https://day.js.org/docs/en/manipulate/utc-offset)
|
||||
- `titleCount`: `50`. Will add "..." and trim if title length bigger.
|
||||
- `titlePrefix`: `""`. Will add before title (e.g. "Note: ")
|
||||
- `ignoreReplies`: `false`. If true, will not process `in-reply-to` items.
|
||||
|
||||
Note that this **does not** delete the notes dir with every call. It simply checks if there isn't already a file with the same name (based on the publication date), and adds one if not.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jam-my-stack",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.14",
|
||||
"repository": {
|
||||
"url": "https://github.com/wgroeneveld/jam-my-stack",
|
||||
"type": "git"
|
||||
|
|
|
@ -50,9 +50,10 @@ function trimIfNeeded(title, count, prefix) {
|
|||
// utcOffset = 60 (in minutes)
|
||||
// titleCount = 50
|
||||
// titlePrefix = "Note: "
|
||||
// ignoreReplies = false
|
||||
|
||||
async function parseMastoFeed(options) {
|
||||
const { notesdir, url, utcOffset = 60, titleCount = 50, titlePrefix = "" } = options
|
||||
const { notesdir, url, utcOffset = 60, titleCount = 50, titlePrefix = "", ignoreReplies = false } = options
|
||||
|
||||
const notesroot = await getFiles(notesdir)
|
||||
const notes = notesroot
|
||||
|
@ -100,6 +101,7 @@ async function parseMastoFeed(options) {
|
|||
day
|
||||
}
|
||||
})
|
||||
.filter(itm => ignoreReplies ? itm.context .length > 0 : true)
|
||||
.filter(itm => !notes.includes(`${itm.year}/${itm.month}/${itm.hash}`))
|
||||
.forEach(itm => convertAtomItemToMd(itm, notesdir))
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ async function getSince(configfile) {
|
|||
async function updateSince(configfile) {
|
||||
const since = new Date().toISOString()
|
||||
await fsp.writeFile(configfile, JSON.stringify({ since }, null, 2), 'utf-8')
|
||||
return since
|
||||
}
|
||||
|
||||
async function sendWebmentions(domain, configfile) {
|
||||
|
@ -28,7 +29,8 @@ async function sendWebmentions(domain, configfile) {
|
|||
|
||||
// this is an async call and will return 202 to say "started sending them out".
|
||||
const result = await got.put(url)
|
||||
await updateSince(configfile)
|
||||
const updatedSince = await updateSince(configfile)
|
||||
return updatedSince
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
<?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/a51e13ce-d618-4602-84f7-f398126510ff</id>
|
||||
<title>Enjoyed an afternoon of oldskool Diablo II on the Europebattle servers. We did a few Mephisto run...</title>
|
||||
<content type="html">Enjoyed an afternoon of oldskool Diablo II on the Europebattle servers. We did a few Mephisto runs, managed to hit Hell, and I re-converetd my druid into a windy one. Good times!</content>
|
||||
<published>2021-03-14T16:41:53.518661Z</published>
|
||||
<updated>2021-03-14T16:41:53.518661Z</updated>
|
||||
<ostatus:conversation ref="https://chat.brainbaking.com/contexts/6c75527a-613c-47a4-9922-47bac2cb9ee5">
|
||||
https://chat.brainbaking.com/contexts/6c75527a-613c-47a4-9922-47bac2cb9ee5
|
||||
</ostatus:conversation>
|
||||
<link href="https://chat.brainbaking.com/contexts/6c75527a-613c-47a4-9922-47bac2cb9ee5" rel="ostatus:conversation"/>
|
||||
|
||||
|
||||
<summary></summary>
|
||||
|
||||
|
||||
|
||||
<link type="application/atom+xml" href='https://chat.brainbaking.com/objects/a51e13ce-d618-4602-84f7-f398126510ff' rel="self"/>
|
||||
<link type="text/html" href='https://chat.brainbaking.com/objects/a51e13ce-d618-4602-84f7-f398126510ff' rel="alternate"/>
|
||||
</entry>
|
||||
|
||||
<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>@StampedingLonghorn I tried to chase him away, but you know how that turned out... 😼 There&#39;s ...</title>
|
||||
<content type="html"><span class="h-card"><a class="u-url mention" data-user="A4nwg4LYyh4WgrJOXg" href="https://social.linux.pizza/@StampedingLonghorn" rel="ugc">@<span>StampedingLonghorn</span></a></span> I tried to chase him away, but you know how that turned out... 😼 There&#39;s even cat hair inside the cases... (to be clear: also unintentional)</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>
|
|
@ -18,6 +18,29 @@ describe("mastodon feed parser tests", () => {
|
|||
fs.mkdirSync(dumpdir)
|
||||
});
|
||||
|
||||
describe("ignore replies option", () => {
|
||||
test("ignore replies if ignoreReplies is set to true", async () => {
|
||||
await parseMastoFeed({
|
||||
url: "masto-feed-with-replies",
|
||||
notesdir: dumpdir,
|
||||
ignoreReplies: true
|
||||
})
|
||||
|
||||
dir = await fsp.readdir(`${dumpdir}/2021/03`, { withFileTypes: true })
|
||||
expect(dir.length).toBe(1)
|
||||
})
|
||||
test("does not ignore replies if ignoreReplies is set to false", async () => {
|
||||
await parseMastoFeed({
|
||||
url: "masto-feed-with-replies",
|
||||
notesdir: dumpdir,
|
||||
ignoreReplies: false
|
||||
})
|
||||
|
||||
dir = await fsp.readdir(`${dumpdir}/2021/03`, { withFileTypes: true })
|
||||
expect(dir.length).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
test("parse embedded images", async () => {
|
||||
await parseMastoFeed({
|
||||
url: "masto-feed-images",
|
||||
|
|
Loading…
Reference in New Issue