]>
git.r.bdr.sh - rbdr/linkding-linkblog-updater/blob - index.js
549e223b4d19aaef488ce24dfd5cbe43175facd8
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(title
, text
) {
18 return `# ${title}\n\n${text}`;
23 const linkText
= posts
.map((post
) => {
25 return `=> ${post.href} ${post.description}\n${post.extended}`;
31 if (posts
.length
=== 1) {
32 return posts
[0].description
;
34 return `${posts.length} links for ${internals.date}`;
39 return text
.toLowerCase().replace(/[^a
-z0
-9 ]/g
, '').replace(/ +/g
, '-')
44 async
function run() {
45 const pinboard
= new Pinboard(internals
.apiToken
);
46 const getPins
= promisify(pinboard
.all
);
47 const addPin
= promisify(pinboard
.add
);
49 const pins
= await
getPins({ tag: 'linkblog' });
51 if (pins
.length
=== 0) {
52 console
.error('No links to post');
56 const title
= internals
.getTitle(posts
);
57 const text
= internals
.getText(posts
);
58 const gemtext
= internals
.generateGemtext(title
, text
);
59 const filename
= internals
.slugify(title
);
61 const gemfile
= resolve(join(__dirname
, `${filename}.gmi`));
62 await
writeFile(gemfile
, gemtext
);
63 await internals
.exec(`blog --add ${gemfile}`);
64 await internals
.exec(`blog --publish ${internals.blogUrl}`);
65 await internals
.exec(`blog --publish-archive ${internals.archiveUrl}`);
68 for (const pin
of pins
) {
71 description: pin
.description
,
72 extended: pin
.extended
,
74 tags: pin
.tags
.replace('linkblog', 'linkblog-posted')
80 .then(() => process
.exit(0))