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

View File

@ -66,6 +66,7 @@ router.get('/', async function (req, res, next) {
console.log('================== calcul de stats désactivé dans index.js ================== ') console.log('================== calcul de stats désactivé dans index.js ================== ')
} }
exportToMarkdown(res) exportToMarkdown(res)
exportToOrgmode(res)
console.log('json files read') console.log('json files read')
res.render('index', { res.render('index', {
title: "Conversion de GTG tâches", title: "Conversion de GTG tâches",
@ -102,12 +103,14 @@ function computeData(jsonConvertedData) {
jsonAllData.all = gtgData jsonAllData.all = gtgData
jsonAllData.stats = { jsonAllData.stats = {
tasksCount : counterOfTasks.length, tasksCount: counterOfTasks.length,
// tasksCount: 0, // tasksCount: 0,
tasksClosed: 0, tasksClosed: 0,
tasksOpen: 0, tasksOpen: 0,
maxTasksCountPerTag: 0, maxTasksCountPerTag: 0,
listTags: [], listTags: [],
tagByKey: {},
listAll: [],
listOpen: [], listOpen: [],
listOpenWeekly: [], listOpenWeekly: [],
listOpenMonthly: [], listOpenMonthly: [],
@ -122,12 +125,17 @@ function computeData(jsonConvertedData) {
jsonAllData.stats.listTags = gtgData.taglist[0].tag jsonAllData.stats.listTags = gtgData.taglist[0].tag
console.log('tasks', gtgData.tasklist[0].task); 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) { for (let taskItem of gtgData.tasklist[0].task) {
// count open and closed tasks // count open and closed tasks
let now = new Date() let now = new Date()
jsonAllData.stats.listAll.push(taskItem)
if (taskItem['$'].status == 'Active') { if (taskItem['$'].status == 'Active') {
jsonAllData.stats.listOpen.push(taskItem) jsonAllData.stats.listOpen.push(taskItem)
let addeddate = new Date(taskItem.addeddate) let addeddate = new Date(taskItem.addeddate)
@ -354,7 +362,7 @@ function exportToMarkdown(res) {
markdownExportData += `\n# Export de toutes les ${jsonAllData.stats.listClosed.length} tâches fermées GTG \n `; markdownExportData += `\n# Export de toutes les ${jsonAllData.stats.listClosed.length} tâches fermées GTG \n `;
markdownExportData += `\n `; markdownExportData += `\n `;
jsonAllData.stats.listClosed.map(elem=>{ jsonAllData.stats.listClosed.map(elem => {
dataTagsMd += `\n * ${elem.title} `; dataTagsMd += `\n * ${elem.title} `;
}) })
@ -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 * transformToJson
* @param xml * @param xml