diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2022-12-20 06:49:16 +0000 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2022-12-20 06:49:16 +0000 |
| commit | 278296c2e8c07f42ca80c31e6c95db4f3bdc96bc (patch) | |
| tree | 12063c5dcaf7be0a3a885502b12e7c66fab1da5f | |
| parent | f0b2faff6e6e69de483fccb940f7fc989c4c9030 (diff) | |
tooting and fixes
| -rw-r--r-- | index.js | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -10,6 +10,7 @@ const internals = { apiToken: process.env.PINBOARD_TOKEN, blogUrl: process.env.BLOG_URL, archiveUrl: process.env.ARCHIVE_URL, + tootToken: process.env.TOOT_TOKEN, date: (new Date()).toISOString().split('T')[0], @@ -20,7 +21,7 @@ const internals = { getText(posts) { - const linkText = posts.map((post) => { + return posts.map((post) => { return `=> ${post.href} ${post.description}\n${post.extended}`; }).join('\n\n'); @@ -29,7 +30,7 @@ const internals = { getTitle(posts) { if (posts.length === 1) { - return posts[0].description; + return `Link: ${posts[0].description}`; } return `${posts.length} links for ${internals.date}`; }, @@ -37,7 +38,24 @@ const internals = { slugify(text) { return text.toLowerCase().replace(/[^a-z0-9 ]/g, '').replace(/ +/g, '-') + }, + + async toot(title) { + + const body = new FormData(); + body.set( + 'status', + `New post: ${title}\n\nAvailable on:\n\nāļø the gemini archive gemini://gemini.unlimited.pizza/gemlog/\n\n or, the ephemeral blog š: https://blog.unlimited.pizza` + ); + return fetch('https://mastodon.social/api/v1/statuses', { + method: 'post', + headers: { + Authorization: `Bearer ${internals.tootToken}`, + }, + body + }); } + }; @@ -53,8 +71,8 @@ async function run() { return; } - const title = internals.getTitle(posts); - const text = internals.getText(posts); + const title = internals.getTitle(pins); + const text = internals.getText(pins); const gemtext = internals.generateGemtext(title, text); const filename = internals.slugify(title); @@ -74,6 +92,10 @@ async function run() { tags: pin.tags.replace('linkblog', 'linkblog-posted') }); } + + if (internals.tootToken) { + await internals.toot(title); + } } run() |