From: Ruben Beltran del Rio Date: Sat, 21 Sep 2024 18:39:12 +0000 (+0000) Subject: Remove references to pinboard X-Git-Url: https://git.r.bdr.sh/rbdr/linkding-linkblog-updater/commitdiff_plain/fdb5251ccba2456745ca43801a6a8ce040177771?ds=sidebyside Remove references to pinboard --- diff --git a/README.md b/README.md index 4b1e893..58cd22e 100644 --- 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 diff --git a/index.js b/index.js index 279594a..ef06ad9 100644 --- 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) { diff --git a/package-lock.json b/package-lock.json index bd3a4f9..3ff7f01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,102 +1,13 @@ { - "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" } } } diff --git a/package.json b/package.json index 689672c..95bf7da 100644 --- a/package.json +++ b/package.json @@ -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": {} }