import fs from "fs"; import path from 'path'; import sendPostMastodon from './utils.mjs' const __dirname = path.resolve(); const list_posts_json = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/qzine_posts_all.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 = list_posts_json.filter(elem => elem.status === 'publish') return getRandomElementOfArray(filteredLinks) } function postLink() { let postObject = getRandomLink() console.log("envoi de post par le compte Qzine - post n°" ,postObject.id) let filteredExcerpt = postObject.excerpt.rendered.replace(/<[^>]+>/g, '') let counterLength = filteredExcerpt.length; let limitExcerpt = 250 filteredExcerpt = filteredExcerpt.substring(0, limitExcerpt) if (filteredExcerpt && counterLength > limitExcerpt) { filteredExcerpt = '> ' + filteredExcerpt + '… ' } let configPost = { author: 'qzine', image: 'qzine_default.jpg', message: `# [ !Qzine - ${postObject.title.rendered}](${postObject.link}) * ${postObject.date} - ${postObject.link} ${filteredExcerpt} * #qzine #qzineblog #blog #sexe #relations #éducation #plaisir #sociologie`, reallySendPost } console.log("configPost.message", configPost.message) sendPostMastodon(configPost) } postLink();