51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
// import fetch from "node-fetch"
|
|
// import rp from "request-promise";
|
|
// import $ from "cheerio";
|
|
import fs from "fs";
|
|
import Masto from "mastodon";
|
|
import path from 'path';
|
|
const __dirname = path.resolve();
|
|
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname +"/assets/documents/tykayn_wptkblog_posts.json", 'utf-8'))
|
|
import {sendPostMastodon} from './utils.js'
|
|
|
|
|
|
|
|
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: 'curator',
|
|
message: `# [${postObject.post_title}](${postObject.guid})
|
|
|
|
* ${postObject.post_date} - ${postObject.guid}
|
|
${filteredExcerpt}
|
|
* #tykayn #tkblog #blog`,
|
|
// reallySendPost: true,
|
|
reallySendPost: false,
|
|
}
|
|
console.log("configPost.message", configPost.message)
|
|
sendPostMastodon(configPost)
|
|
}
|
|
|
|
postLink(); |