58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
import fs from "fs";
|
|
import path from 'path';
|
|
import {
|
|
randomIntFromInterval,
|
|
findPictureAndSendPost, getRandomLinkGeneral, hasCliArgument, slugify
|
|
|
|
} from './libs/utils.mjs'
|
|
import Masto from "mastodon";
|
|
|
|
const __dirname = path.resolve();
|
|
const folderBlogPostsPreview = process.cwd() + '/assets/blog_posts_medias/'
|
|
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/tykayn_wptkblog_posts.json", 'utf-8'))
|
|
|
|
|
|
|
|
|
|
function postLink() {
|
|
let postObject = {};
|
|
let idOfPost = 1930;
|
|
idOfPost = null;
|
|
|
|
if (idOfPost) {
|
|
postObject = tkpostsjson.filter(elem => elem.ID === idOfPost)[0]
|
|
console.log(postObject)
|
|
} else {
|
|
|
|
postObject = getRandomLinkGeneral(tkpostsjson)
|
|
}
|
|
console.log("envoi de post par tykayn")
|
|
|
|
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: 'tykayn_blog',
|
|
slug: slugify(postObject.post_title),
|
|
postObject,
|
|
folder_image: folderBlogPostsPreview,
|
|
image: 'tk_blog_bannieres_oct2010-' + randomIntFromInterval(1, 9) + '.jpg',
|
|
message: `# [${postObject.post_title}](${postObject.guid})
|
|
|
|
* ${postObject.guid}
|
|
|
|
> "${filteredExcerpt}"
|
|
* #tykayn #tkblog #blog`,
|
|
}
|
|
// ajouter la première image du post de blog
|
|
findPictureAndSendPost(postObject.post_content, configPost)
|
|
|
|
}
|
|
|
|
postLink(); |