2022-08-04 23:07:59 +02:00
|
|
|
import fs from "fs";
|
|
|
|
import path from 'path';
|
2022-11-22 10:55:11 +01:00
|
|
|
import sendPostMastodon, {randomIntFromInterval, findFirstImageInContent} from './utils.mjs'
|
2022-08-04 23:07:59 +02:00
|
|
|
|
2022-08-08 18:43:26 +02:00
|
|
|
const __dirname = path.resolve();
|
2022-11-22 10:55:11 +01:00
|
|
|
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/cipherbliss_tkwp_posts.json", 'utf-8'))
|
|
|
|
const reallySendPost = false;
|
|
|
|
// const reallySendPost = true;
|
2022-08-04 23:07:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
export function getRandomElementOfArray(listItems) {
|
|
|
|
return listItems[Math.floor(Math.random() * listItems.length)]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getRandomLink() {
|
|
|
|
let filteredLinks = tkpostsjson.filter(elem => elem.post_status === 'publish')
|
|
|
|
return getRandomElementOfArray(filteredLinks)
|
|
|
|
}
|
|
|
|
|
|
|
|
function postLink() {
|
|
|
|
|
|
|
|
let postObject = getRandomLink()
|
2022-11-22 10:55:11 +01:00
|
|
|
console.log("envoi de post de blog cipherbliss par le compte tykayn")
|
2022-08-04 23:07:59 +02:00
|
|
|
|
|
|
|
let filteredExcerpt = postObject.post_content.replace(/<[^>]+>/g, '')
|
|
|
|
let counterLength = filteredExcerpt.length;
|
|
|
|
|
|
|
|
let limitExcerpt = 250
|
|
|
|
filteredExcerpt = filteredExcerpt.substring(0, limitExcerpt)
|
2022-08-08 18:43:26 +02:00
|
|
|
if (filteredExcerpt && counterLength > limitExcerpt) {
|
2022-08-08 22:33:06 +02:00
|
|
|
filteredExcerpt = ' _ ' + filteredExcerpt + '… _'
|
2022-08-04 23:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let configPost = {
|
2022-08-08 18:25:37 +02:00
|
|
|
author: 'tykayn',
|
2022-11-22 10:55:11 +01:00
|
|
|
image: 'cipherbliss_post_' + randomIntFromInterval(1 - 3) + '.jpg',
|
2022-11-22 11:27:54 +01:00
|
|
|
message: `# [${postObject.post_title}](https://www.cipherbliss.com/${postObject.post_name})
|
2022-08-04 23:07:59 +02:00
|
|
|
|
|
|
|
* ${postObject.post_date} - ${postObject.guid}
|
|
|
|
${filteredExcerpt}
|
2022-11-22 10:55:11 +01:00
|
|
|
* #tykayn #cipherbliss #blog`,
|
2022-08-08 18:43:26 +02:00
|
|
|
reallySendPost
|
2022-08-04 23:07:59 +02:00
|
|
|
}
|
2022-08-05 14:35:47 +02:00
|
|
|
console.log("configPost.message", configPost.message)
|
2022-11-22 10:55:11 +01:00
|
|
|
|
2022-11-22 11:27:54 +01:00
|
|
|
|
2022-08-04 23:07:59 +02:00
|
|
|
sendPostMastodon(configPost)
|
2022-11-22 11:27:54 +01:00
|
|
|
console.log("post ID: ", postObject.ID)
|
2022-08-04 23:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
postLink();
|