Fixed quotes and links
This commit is contained in:
parent
ab01098653
commit
744767a9e2
3 changed files with 21 additions and 6 deletions
17
main.js
17
main.js
|
@ -1,8 +1,9 @@
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { RichText, BskyAgent } = require("@atproto/api");
|
const { RichText, AtpAgent } = require("@atproto/api");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
const he = require('he');
|
||||||
|
|
||||||
// Mastodon credentials
|
// Mastodon credentials
|
||||||
const mastodonInstance = process.env.MASTODON_INSTANCE;
|
const mastodonInstance = process.env.MASTODON_INSTANCE;
|
||||||
|
@ -10,7 +11,7 @@ const mastodonUser = process.env.MASTODON_USER;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
// Bluesky agent
|
// Bluesky agent
|
||||||
const agent = new BskyAgent({ service: process.env.BLUESKY_ENDPOINT });
|
const agent = new AtpAgent({ service: process.env.BLUESKY_ENDPOINT });
|
||||||
const loginResponse = await agent.login({
|
const loginResponse = await agent.login({
|
||||||
identifier: process.env.BLUESKY_HANDLE,
|
identifier: process.env.BLUESKY_HANDLE,
|
||||||
password: process.env.BLUESKY_PASSWORD,
|
password: process.env.BLUESKY_PASSWORD,
|
||||||
|
@ -57,7 +58,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function postToBluesky(textParts) {
|
async function postToBluesky(textParts) {
|
||||||
const rootMessageResponse = await agent.post(await createBlueskyMessage(textParts[0]));
|
const blueskyMessage = await createBlueskyMessage(textParts[0]);
|
||||||
|
const rootMessageResponse = await agent.post(blueskyMessage);
|
||||||
|
|
||||||
if (textParts.length === 1) return;
|
if (textParts.length === 1) return;
|
||||||
|
|
||||||
|
@ -73,8 +75,11 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeHtmlTags(input) {
|
function sanitizeHtml(input) {
|
||||||
return input.replace(/<[^>]*>/g, "");
|
const withoutHtml = input.replace(/<[^>]*>/g, "");
|
||||||
|
const decodeQuotes = he.decode(withoutHtml);
|
||||||
|
const addSpace = decodeQuotes.replace(/(https?:\/\/)/g, ' $1');
|
||||||
|
return addSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitText(text, maxLength) {
|
function splitText(text, maxLength) {
|
||||||
|
@ -127,7 +132,7 @@ async function main() {
|
||||||
if (currentTimestampId > lastProcessedPostId && lastProcessedPostId != 0) {
|
if (currentTimestampId > lastProcessedPostId && lastProcessedPostId != 0) {
|
||||||
try {
|
try {
|
||||||
console.log('📧 posting to BlueSky', currentTimestampId)
|
console.log('📧 posting to BlueSky', currentTimestampId)
|
||||||
const textParts = splitText(removeHtmlTags(item.object.content), 300);
|
const textParts = splitText(sanitizeHtml(item.object.content), 300);
|
||||||
postToBluesky(textParts);
|
postToBluesky(textParts);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('🔥 can\'t post to Bluesky', currentTimestampId, error)
|
console.error('🔥 can\'t post to Bluesky', currentTimestampId, error)
|
||||||
|
|
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -14,6 +14,7 @@
|
||||||
"@semantic-release/git": "^10.0.1",
|
"@semantic-release/git": "^10.0.1",
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
|
"he": "^1.2.0",
|
||||||
"mastodon-api": "^1.3.0"
|
"mastodon-api": "^1.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3097,6 +3098,14 @@
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/he": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
|
||||||
|
"bin": {
|
||||||
|
"he": "bin/he"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/highlight.js": {
|
"node_modules/highlight.js": {
|
||||||
"version": "10.7.3",
|
"version": "10.7.3",
|
||||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz",
|
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz",
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
"@semantic-release/git": "^10.0.1",
|
"@semantic-release/git": "^10.0.1",
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
|
"he": "^1.2.0",
|
||||||
"mastodon-api": "^1.3.0"
|
"mastodon-api": "^1.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue