2022-08-04 23:07:59 +02:00
|
|
|
import fs from "fs";
|
|
|
|
import path from 'path';
|
2022-12-14 16:38:47 +01:00
|
|
|
import {
|
|
|
|
randomIntFromInterval,
|
2022-12-14 17:31:03 +01:00
|
|
|
findPictureAndSendPost, getRandomLinkGeneral, hasCliArgument, slugify
|
2022-12-14 16:47:57 +01:00
|
|
|
|
2023-03-04 22:53:12 +01:00
|
|
|
} from './libs/utils.mjs'
|
2022-12-07 23:15:07 +01:00
|
|
|
import Masto from "mastodon";
|
2022-08-04 23:07:59 +02:00
|
|
|
|
2022-08-08 18:43:26 +02:00
|
|
|
const __dirname = path.resolve();
|
2022-12-07 23:15:07 +01:00
|
|
|
const folderBlogPostsPreview = process.cwd() + '/assets/blog_posts_medias/'
|
2022-08-08 18:43:26 +02:00
|
|
|
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/tykayn_wptkblog_posts.json", 'utf-8'))
|
2022-12-07 23:15:07 +01:00
|
|
|
|
|
|
|
|
2022-08-04 23:07:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
function postLink() {
|
2022-12-14 17:31:03 +01:00
|
|
|
let postObject = {};
|
|
|
|
let idOfPost = 1930;
|
|
|
|
idOfPost = null;
|
2022-12-14 17:39:01 +01:00
|
|
|
|
2022-12-14 17:31:03 +01:00
|
|
|
if (idOfPost) {
|
|
|
|
postObject = tkpostsjson.filter(elem => elem.ID === idOfPost)[0]
|
|
|
|
console.log(postObject)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
postObject = getRandomLinkGeneral(tkpostsjson)
|
|
|
|
}
|
2022-12-07 23:15:07 +01:00
|
|
|
console.log("envoi de post par tykayn")
|
2022-08-04 23:07:59 +02:00
|
|
|
|
|
|
|
let filteredExcerpt = postObject.post_content.replace(/<[^>]+>/g, '')
|
|
|
|
let counterLength = filteredExcerpt.length;
|
|
|
|
let limitExcerpt = 250
|
|
|
|
filteredExcerpt = filteredExcerpt.substring(0, limitExcerpt)
|
2022-08-08 18:43:26 +02:00
|
|
|
if (filteredExcerpt && counterLength > limitExcerpt) {
|
2022-08-08 22:33:06 +02:00
|
|
|
filteredExcerpt = ' _ ' + filteredExcerpt + '… _'
|
2022-08-04 23:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let configPost = {
|
2022-08-08 18:25:37 +02:00
|
|
|
author: 'tykayn',
|
2022-12-14 16:38:47 +01:00
|
|
|
website: 'tykayn_blog',
|
2022-12-14 17:31:03 +01:00
|
|
|
slug: slugify(postObject.post_title),
|
2022-12-14 16:38:47 +01:00
|
|
|
postObject,
|
|
|
|
folder_image: folderBlogPostsPreview,
|
2022-12-14 17:31:03 +01:00
|
|
|
image: 'tk_blog_bannieres_oct2010-' + randomIntFromInterval(1, 9) + '.jpg',
|
2022-08-04 23:07:59 +02:00
|
|
|
message: `# [${postObject.post_title}](${postObject.guid})
|
|
|
|
|
2022-12-14 16:38:47 +01:00
|
|
|
* ${postObject.guid}
|
2022-12-14 17:31:03 +01:00
|
|
|
|
|
|
|
> "${filteredExcerpt}"
|
2022-08-04 23:07:59 +02:00
|
|
|
* #tykayn #tkblog #blog`,
|
|
|
|
}
|
2022-12-07 23:15:07 +01:00
|
|
|
// ajouter la première image du post de blog
|
2022-12-14 16:38:47 +01:00
|
|
|
findPictureAndSendPost(postObject.post_content, configPost)
|
2022-12-07 23:15:07 +01:00
|
|
|
|
2022-08-04 23:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
postLink();
|