import fs from "fs"; import path from 'path'; import sendPostMastodon, {randomIntFromInterval} from './utils.mjs' const __dirname = path.resolve(); const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/tykayn_wptkblog_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 par le Curator") 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: 'tk_blog_bannieres_oct2010-' + randomIntFromInterval(1 - 10) + '.jpg', message: `# [${postObject.post_title}](${postObject.guid}) * ${postObject.post_date} - ${postObject.guid} ${filteredExcerpt} * #tykayn #tkblog #blog`, reallySendPost } console.log("configPost.message", configPost.message) sendPostMastodon(configPost) } postLink();