88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import * as blog_posts from './extractions_bdd/mastodon_statuses.json';
|
|
|
|
import {v4 as uuidv4} from 'uuid';
|
|
import moment = require('moment');
|
|
|
|
const fs = require('fs');
|
|
// get all posts
|
|
// @ts-ignore
|
|
console.log('posts length', blog_posts.length);
|
|
let ii = 0;
|
|
let real_post_ii = 0;
|
|
let max_counter = 3000;
|
|
// max_counter = 3;
|
|
let now: any = new Date();
|
|
now = now.getUTCDate();
|
|
let blog_name = 'cipherbliss_blog'; // slug
|
|
let blog_title = 'Cipherbliss blog'; // text title
|
|
let liens_bottom = '- cipherbliss [[id:cd68065a-9ede-4c9a-a26c-069c2d51f578][' + blog_title + ']]\n';
|
|
let lists_of_links_org = [];
|
|
let indexUUID = uuidv4();
|
|
|
|
var pandoc = require('pandoc');
|
|
|
|
async function loopOnJson() {
|
|
|
|
// loop time
|
|
|
|
let filecontent = '* Status Mastodon ';
|
|
|
|
// @ts-ignore
|
|
blog_posts.map((post: any) => {
|
|
ii++;
|
|
if (ii < max_counter && (post.text !== '')) {
|
|
filecontent += '** '+post.created_at+'\n'
|
|
|
|
+ post.text +'\n'
|
|
+ '[['+post.uri +']]\n'
|
|
}
|
|
|
|
})
|
|
writeNewFile('mastodon_statuses.org', filecontent);
|
|
|
|
}
|
|
|
|
function writeNewFile(fileName, fileContent) {
|
|
console.log('write file ', fileName);
|
|
return fs.writeFile(
|
|
`./output/${fileName}`,
|
|
fileContent,
|
|
"utf8",
|
|
(err: any) => {
|
|
if (err) {
|
|
console.log(`Error writing file: ${err}`);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function makeIndexOfFiles(lists_of_links_org) {
|
|
console.log('write index', lists_of_links_org.length, 'links');
|
|
// make an org file for each
|
|
|
|
let list_of_links_content = '';
|
|
|
|
lists_of_links_org.reverse().forEach(pair => {
|
|
list_of_links_content += `\n** <${pair.date}> [[id:${pair.org_id}][${pair.title}]]`
|
|
})
|
|
|
|
let file_index_content = `
|
|
:PROPERTIES:
|
|
:ID: ${indexUUID}
|
|
:END:
|
|
#+title: ${blog_name}_index
|
|
|
|
* Index des articles Org
|
|
${list_of_links_content}
|
|
`;
|
|
var today = moment().format('YYYYMMDDHHmmss');
|
|
console.log(today, 'list_of_links_content', file_index_content);
|
|
writeNewFile(today + '__' + blog_name + '_index.org', file_index_content);
|
|
}
|
|
|
|
loopOnJson().catch(err => console.log(err))
|
|
//.then(r => console.log('response', r))
|
|
;
|
|
|
|
|