multi-account-post-schedule.../helpers/cipherbliss_post.mjs
2022-11-22 11:27:54 +01:00

52 lines
1.6 KiB
JavaScript

import fs from "fs";
import path from 'path';
import sendPostMastodon, {randomIntFromInterval, findFirstImageInContent} from './utils.mjs'
const __dirname = path.resolve();
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/cipherbliss_tkwp_posts.json", 'utf-8'))
const reallySendPost = false;
// const reallySendPost = true;
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()
console.log("envoi de post de blog cipherbliss par le compte tykayn")
let filteredExcerpt = postObject.post_content.replace(/<[^>]+>/g, '')
let counterLength = filteredExcerpt.length;
let limitExcerpt = 250
filteredExcerpt = filteredExcerpt.substring(0, limitExcerpt)
if (filteredExcerpt && counterLength > limitExcerpt) {
filteredExcerpt = ' _ ' + filteredExcerpt + '… _'
}
let configPost = {
author: 'tykayn',
image: 'cipherbliss_post_' + randomIntFromInterval(1 - 3) + '.jpg',
message: `# [${postObject.post_title}](https://www.cipherbliss.com/${postObject.post_name})
* ${postObject.post_date} - ${postObject.guid}
${filteredExcerpt}
* #tykayn #cipherbliss #blog`,
reallySendPost
}
console.log("configPost.message", configPost.message)
sendPostMastodon(configPost)
console.log("post ID: ", postObject.ID)
}
postLink();