58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
import fs from "fs";
|
|
import path from 'path';
|
|
import sendPostMastodon, {
|
|
randomIntFromInterval,
|
|
findFirstImageInContent,
|
|
findPictureAndSendPost,
|
|
getRandomElementOfArray
|
|
} from './libs/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;
|
|
|
|
|
|
|
|
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',
|
|
website: 'cipherbliss',
|
|
slug: postObject.post_name,
|
|
postObject,
|
|
folder_image: folderBlogPostsPreview,
|
|
image: 'cipherbliss_post_' + randomIntFromInterval(1 , 3) + '.jpg',
|
|
message: `# [${postObject.post_title}](https://www.cipherbliss.com/${postObject.post_name})
|
|
|
|
" ${filteredExcerpt} "
|
|
* #tykayn #cipherbliss #blog`,
|
|
reallySendPost
|
|
}
|
|
console.log("configPost.message", configPost.message)
|
|
console.log("configPost.image", configPost.image)
|
|
|
|
|
|
findPictureAndSendPost(postObject.content.rendered, configPost)
|
|
console.log("post ID: ", postObject.ID)
|
|
}
|
|
|
|
postLink(); |