]> git.r.bdr.sh - rbdr/linkding-linkblog-updater/commitdiff
Remove references to pinboard
authorRuben Beltran del Rio <redacted>
Sat, 21 Sep 2024 18:39:12 +0000 (18:39 +0000)
committerRuben Beltran del Rio <redacted>
Sat, 21 Sep 2024 18:39:12 +0000 (18:39 +0000)
README.md
index.js
package-lock.json
package.json

index 4b1e8933c17510dff8a45bb7c8fc1b79e216fc9b..58cd22ef85146c30e3c5f6a84a5ed3a33d72d1f5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
-# Pinboard Linkblog Updater
+# Linkding Linkblog Updater
 
 This only works with [blog][blog].
 
-
 [blog]: https://git.sr.ht/~rbdr/blog
index 279594aa6403152f991cff9cbf09404ab7d625f4..ef06ad9301dd27f5f3085d8dfded3f574170fcbc 100644 (file)
--- a/index.js
+++ b/index.js
@@ -2,12 +2,12 @@ const { exec } = require('child_process');
 const { resolve, join} = require('path');
 const { rm, writeFile } = require('fs/promises');
 const { promisify } = require('util');
-const Pinboard = require('node-pinboard').default;
 
 const internals = {
   exec: promisify(exec),
 
-  apiToken: process.env.PINBOARD_TOKEN,
+  apiUrl: process.env.API_URL,
+  apiToken: process.env.API_TOKEN,
   blogUrl: process.env.BLOG_URL,
   archiveUrl: process.env.ARCHIVE_URL,
   blogPublicUrl: process.env.BLOG_PUBLIC_URL,
@@ -26,14 +26,14 @@ const internals = {
 
     return posts.map((post) => {
 
-      return `=> ${post.href} ${post.description}\n${post.extended}`;
+      return `=> ${post.url} ${post.title}\n${post.notes}`;
     }).join('\n\n');
   },
 
   getTitle(posts) {
 
     if (posts.length === 1) {
-      return `Link: ${posts[0].description}`;
+      return `Link: ${posts[0].title}`;
     }
     return `${posts.length} links for ${internals.date}`;
   },
@@ -51,29 +51,64 @@ const internals = {
       `New post: ${title}\n\nAvailable on:\n\nā™Šļø the gemini archive ${internals.archivePublicUrl}\n\n or, the ephemeral blog šŸŒ: ${internals.blogPublicUrl}`
     );
     return fetch(`https://${internals.mastodonDomain}/api/v1/statuses`, {
-      method: 'post',
+      method: 'POST',
       headers: {
         Authorization: `Bearer ${internals.tootToken}`,
       },
       body
     });
-  }
+  },
+
+  async getBookmarks() {
+
+    const url = join(internals.apiUrl, 'bookmarks') + '?q=%23linkblog';
+    const response = await fetch(url, {
+      headers: {
+        'Content-Type': 'application/json',
+        Authorization: `Token ${internals.apiToken}`
+      }
+    });
+    const data = await response.json();
+
+    return data.results;
+  },
 
+  async updateBookmark(bookmark) {
+
+    console.log(bookmark.tag_names);
+    console.log(bookmark.tag_names.map((tag) => tag === 'linkblog' ? 'linkblog-posted' : tag));
+
+    const url = join(internals.apiUrl, 'bookmarks', `${bookmark.id}`)
+    const response = await fetch(url, {
+      method: 'PATCH',
+      body: JSON.stringify(
+        {
+          tag_names: bookmark.tag_names.map((tag) => tag === 'linkblog' ? 'linkblog-posted' : tag)
+        }
+      ),
+      headers: {
+        'Content-Type': 'application/json',
+        Authorization: `Token ${internals.apiToken}`
+      }
+    });
+
+    const data = await response.text();
+    console.log(url);
+    console.log(data);
+  }
 };
 
 
 async function run() {
-  const pinboard = new Pinboard(internals.apiToken);
+  const bookmarks = await internals.getBookmarks();
 
-  const pins = await pinboard.all({ tag: 'linkblog' });
-
-  if (pins.length === 0) {
+  if (bookmarks.length === 0) {
     console.error('No links to post');
     return;
   }
 
-  const title = internals.getTitle(pins);
-  const text = internals.getText(pins);
+  const title = internals.getTitle(bookmarks);
+  const text = internals.getText(bookmarks);
   const gemtext = internals.generateGemtext(title, text);
   const filename = internals.slugify(title);
 
@@ -84,14 +119,8 @@ async function run() {
   await internals.exec(`blog publish-archive ${internals.archiveUrl}`);
   await rm(gemfile);
 
-  for (const pin of pins) {
-    await pinboard.add({
-      url: pin.href,
-      description: pin.description,
-      extended: pin.extended,
-      dt: pin.time,
-      tags: pin.tags.replace('linkblog', 'linkblog-posted')
-    });
+  for (const bookmark of bookmarks) {
+    await internals.updateBookmark(bookmark);
   }
 
   if (internals.tootToken) {
index bd3a4f92d8896cf56f9b9f25fca3e297cfc6eead..3ff7f01980d21376d6301dd0c58b0655575d46e1 100644 (file)
 {
-  "name": "pinboard-linkblog-updater",
-  "version": "1.0.0",
+  "name": "linkding-linkblog-updater",
+  "version": "2.0.0",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
-      "name": "pinboard-linkblog-updater",
-      "version": "1.0.0",
-      "license": "Apache-2.0",
-      "dependencies": {
-        "node-pinboard": "^2.0.1"
-      }
-    },
-    "node_modules/node-fetch": {
-      "version": "2.6.7",
-      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
-      "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
-      "dependencies": {
-        "whatwg-url": "^5.0.0"
-      },
-      "engines": {
-        "node": "4.x || >=6.0.0"
-      },
-      "peerDependencies": {
-        "encoding": "^0.1.0"
-      },
-      "peerDependenciesMeta": {
-        "encoding": {
-          "optional": true
-        }
-      }
-    },
-    "node_modules/node-pinboard": {
-      "version": "2.0.1",
-      "resolved": "https://registry.npmjs.org/node-pinboard/-/node-pinboard-2.0.1.tgz",
-      "integrity": "sha512-TvFjnLQRW/mEJmBDbBaL3APOxx1bCxCt1iw37YqgtLzWNUnu9zez2JTARd4qjcXp6uvJ8oaRhFNRJsLBhR7epQ==",
-      "dependencies": {
-        "node-fetch": "^2.6.0"
-      },
-      "engines": {
-        "node": ">= 8.0"
-      }
-    },
-    "node_modules/tr46": {
-      "version": "0.0.3",
-      "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
-      "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
-    },
-    "node_modules/webidl-conversions": {
-      "version": "3.0.1",
-      "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
-      "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
-    },
-    "node_modules/whatwg-url": {
-      "version": "5.0.0",
-      "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
-      "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
-      "dependencies": {
-        "tr46": "~0.0.3",
-        "webidl-conversions": "^3.0.0"
-      }
-    }
-  },
-  "dependencies": {
-    "node-fetch": {
-      "version": "2.6.7",
-      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
-      "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
-      "requires": {
-        "whatwg-url": "^5.0.0"
-      }
-    },
-    "node-pinboard": {
-      "version": "2.0.1",
-      "resolved": "https://registry.npmjs.org/node-pinboard/-/node-pinboard-2.0.1.tgz",
-      "integrity": "sha512-TvFjnLQRW/mEJmBDbBaL3APOxx1bCxCt1iw37YqgtLzWNUnu9zez2JTARd4qjcXp6uvJ8oaRhFNRJsLBhR7epQ==",
-      "requires": {
-        "node-fetch": "^2.6.0"
-      }
-    },
-    "tr46": {
-      "version": "0.0.3",
-      "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
-      "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
-    },
-    "webidl-conversions": {
-      "version": "3.0.1",
-      "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
-      "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
-    },
-    "whatwg-url": {
-      "version": "5.0.0",
-      "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
-      "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
-      "requires": {
-        "tr46": "~0.0.3",
-        "webidl-conversions": "^3.0.0"
-      }
+      "name": "linkding-linkblog-updater",
+      "version": "2.0.0",
+      "license": "Apache-2.0"
     }
   }
 }
index 689672ca9b92f150551a7b14037d4966129622b7..95bf7da3a7e9a021c49b4c355e8255450bd07b40 100644 (file)
@@ -1,22 +1,20 @@
 {
-  "name": "pinboard-linkblog-updater",
-  "version": "1.0.0",
-  "description": "A linkblog automation for blog, using pinboard as a source, intended to run with cron",
+  "name": "linkding-linkblog-updater",
+  "version": "2.0.0",
+  "description": "A linkblog automation for blog, using linkding as a source, intended to run with cron",
   "main": "index.js",
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "repository": {
     "type": "git",
-    "url": "git+ssh://git@git.sr.ht/~rbdr/pinboard-linkblog-updater.git"
+    "url": "git+ssh://git@git.sr.ht/~rbdr/linkding-linkblog-updater.git"
   },
   "author": "",
   "license": "Apache-2.0",
   "bugs": {
-    "url": "https://todo.sr.ht/~rbdr/pinboard-linkblog-updater"
+    "url": "https://todo.sr.ht/~rbdr/linkding-linkblog-updater"
   },
-  "homepage": "https://git.sr.ht/~rbdr/pinboard-linkblog-updater#readme",
-  "dependencies": {
-    "node-pinboard": "^2.0.1"
-  }
+  "homepage": "https://git.sr.ht/~rbdr/linkding-linkblog-updater#readme",
+  "dependencies": {}
 }