]> git.r.bdr.sh - rbdr/linkding-linkblog-updater/commitdiff
Add publishing
authorRuben Beltran del Rio <redacted>
Fri, 9 Dec 2022 21:56:40 +0000 (22:56 +0100)
committerRuben Beltran del Rio <redacted>
Fri, 9 Dec 2022 21:56:40 +0000 (22:56 +0100)
index.js

index 78c3d267e72ad10776b3389122ed0c66149b73ae..e1aaebf3a15759f32a5f7dec2d1b46ceb4c822ce 100644 (file)
--- a/index.js
+++ b/index.js
@@ -1,13 +1,16 @@
 const { exec } = require('child_process');
 const { resolve, join} = require('path');
 const { rm, writeFile } = require('fs/promises');
-const { debuglog, promisify } = require('util');
+const { promisify } = require('util');
 const Pinboard = require('node-pinboard').default;
 
 const internals = {
   exec: promisify(exec),
-  debuglog: debuglog('blog'),
+
   apiToken: process.env.PINBOARD_TOKEN,
+  blogUrl: process.env.BLOG_URL,
+  archiveUrl: process.env.ARCHIVE_URL,
+
   date: (new Date()).toISOString().split('T')[0],
 
   generateGemtext(posts) {
@@ -28,28 +31,22 @@ async function run() {
   const getPins = promisify(pinboard.get);
   const addPin = promisify(pinboard.add);
 
-  internals.debuglog('Fetching Pins');
   const pins = await getPins({ tag: 'linkblog' });
 
-  internals.debuglog(`Found ${pins.posts.length} pins`);
   if (pins.posts.length === 0) {
     console.error('No links to post');
     return;
   }
 
-  internals.debuglog('Generating gemtext');
   const gemtext = internals.generateGemtext(pins.posts);
   const gemfile = resolve(join(__dirname, `linkblog-${internals.date}.gmi`));
-  internals.debuglog(`Writing to ${gemfile}`);
   await writeFile(gemfile, gemtext);
-  internals.debuglog('Adding gemfile to log');
-  const output = await internals.exec(`blog --add ${gemfile}`);
-  internals.debuglog(output.stderr);
-  internals.debuglog(`Removing ${gemfile}`);
+  await internals.exec(`blog --add ${gemfile}`);
+  await internals.exec(`blog --publish ${internals.blogUrl}`);
+  await internals.exec(`blog --publish-archive ${internals.archiveUrl}`);
   await rm(gemfile);
 
   for (const pin of pins.posts) {
-    internals.debuglog(`Updating ${pin.href}`);
     await addPin({
       url: pin.href,
       description: pin.description,