convert to orgmode single file

This commit is contained in:
Tykayn 2021-09-10 15:41:27 +02:00 committed by tykayn
parent f4ac8fcd22
commit 43d798085c
1 changed files with 65 additions and 9 deletions

View File

@ -66,6 +66,7 @@ router.get('/', async function (req, res, next) {
console.log('================== calcul de stats désactivé dans index.js ================== ')
}
exportToMarkdown(res)
exportToOrgmode(res)
console.log('json files read')
res.render('index', {
title: "Conversion de GTG tâches",
@ -108,6 +109,8 @@ function computeData(jsonConvertedData) {
tasksOpen: 0,
maxTasksCountPerTag: 0,
listTags: [],
tagByKey: {},
listAll: [],
listOpen: [],
listOpenWeekly: [],
listOpenMonthly: [],
@ -122,12 +125,17 @@ function computeData(jsonConvertedData) {
jsonAllData.stats.listTags = gtgData.taglist[0].tag
console.log('tasks', gtgData.tasklist[0].task);
for (let tagItem of jsonAllData.stats.listTags) {
jsonAllData.stats.tagByKey[tagItem["$"].id] = tagItem["$"]
}
for (let taskItem of gtgData.tasklist[0].task) {
// count open and closed tasks
let now = new Date()
jsonAllData.stats.listAll.push(taskItem)
if (taskItem['$'].status == 'Active') {
jsonAllData.stats.listOpen.push(taskItem)
let addeddate = new Date(taskItem.addeddate)
@ -391,6 +399,54 @@ function exportToMarkdown(res) {
}
function exportToOrgmode(res) {
console.log('jsonAllData.stats.tagByKey', jsonAllData.stats.tagByKey);
let orgmodeContent = `# Tâches exportées
`;
jsonAllData.stats.listAll.map(elem => {
orgmodeContent += `\n*`;
if(elem.$.status === 'Active'){
orgmodeContent += `TODO`;
}
if(elem.$.status === 'Done'){
orgmodeContent += `DONE`;
}
if(elem.$.status === 'Dismiss'){
orgmodeContent += `CANCELED`;
}
orgmodeContent += ` ${elem.title} `;
if (elem.tags[0]) {
elem.tags[0].tag.map(tag => {
// console.log('tag', tag);
// console.log('jsonAllData.stats.tagByKey[tag]', jsonAllData.stats.tagByKey[tag]);
if (tag) {
orgmodeContent += `:${jsonAllData.stats.tagByKey[tag].name}: `;
// orgmodeContent += `:${tag}: `;
}
})
}
})
// write file to disk
fs.writeFile(`output/export_tasks.org`, orgmodeContent, `utf8`, (err) => {
if (err) {
console.log(`Error writing file: ${err}`);
res.send(err)
} else {
console.log(`File \`output/export_tasks.org\` is written successfully!`);
}
});
}
/**
* transformToJson
* @param xml