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')) let reallySendPost = false; 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') filteredLinks = filteredLinks.filter(elem => elem.post_type === 'post') return getRandomElementOfArray(filteredLinks) } function postLink() { let postObject = getRandomLink() console.log("envoi de post de blog cipherbliss par le compte tykayn") console.log(postObject) 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} > ${filteredExcerpt} * #tykayn #cipherbliss #blog`, reallySendPost } console.log("configPost.message", configPost.message) console.log("configPost.image", configPost.image) sendPostMastodon(configPost) console.log("post ID: ", postObject.ID) } postLink();