]>
git.r.bdr.sh - rbdr/linkding-linkblog-updater/blob - index.js
1 const { exec
} = require('child_process');
2 const { resolve
, join
} = require('path');
3 const { rm
, writeFile
} = require('fs/promises');
4 const { promisify
} = require('util');
5 const Pinboard
= require('node-pinboard').default;
10 apiToken: process
.env
.PINBOARD_TOKEN
,
11 blogUrl: process
.env
.BLOG_URL
,
12 archiveUrl: process
.env
.ARCHIVE_URL
,
14 date: (new Date()).toISOString().split('T')[0],
16 generateGemtext(posts
) {
18 const title
= posts
.length
=== 1 ? 'A link' : `${posts.length} links`;
20 const linkText
= posts
.map((pin
) => {
21 return `=> ${pin.href} ${pin.description}\n${pin.extended}`;
24 return `# ${title} for ${internals.date}\n\n${linkText}`;
29 async
function run() {
30 const pinboard
= new Pinboard(internals
.apiToken
);
31 const getPins
= promisify(pinboard
.get);
32 const addPin
= promisify(pinboard
.add
);
34 const pins
= await
getPins({ tag: 'linkblog' });
36 if (pins
.posts
.length
=== 0) {
37 console
.error('No links to post');
41 const gemtext
= internals
.generateGemtext(pins
.posts
);
42 const gemfile
= resolve(join(__dirname
, `linkblog-${internals.date}.gmi`));
43 await
writeFile(gemfile
, gemtext
);
44 await internals
.exec(`blog --add ${gemfile}`);
45 await internals
.exec(`blog --publish ${internals.blogUrl}`);
46 await internals
.exec(`blog --publish-archive ${internals.archiveUrl}`);
49 for (const pin
of pins
.posts
) {
52 description: pin
.description
,
53 extended: pin
.extended
,
55 tags: pin
.tags
.replace('linkblog', 'linkblog-posted')
61 .then(() => process
.exit(0))