org-report-stats/emploi-du-temps/folder_from_tasks.mjs

88 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

/**
* création d'emploi du temps avec des zones découpées en catégorie
* cela permet de parcourir tous les aspects de la méthodologie PARA sur différents créneaux
* @type {{duration: string, start: string, content: null}}
*/
import fs from 'node-fs';
2023-02-06 14:42:26 +01:00
//import tasksList from './../sources/tasks.json' assert { type: "json" };
2023-09-22 15:47:12 +02:00
import tasksList from '/home/tykayn/Nextcloud/ressources/social sorting/output/emacs_export_tasks.json' assert { type: "json" };
let folderPrefix = './emploi-du-temps/folders_build';
async function foldersGeneration(dirpath){
2023-09-22 15:47:12 +02:00
if(dirpath.length > 30){
dirpath = dirpath.slice(0,30)
}
await fs.promises.mkdir(`${folderPrefix}/${dirpath}`, { recursive: true })
}
export let sectionsCleaned = {}
2023-02-06 14:42:26 +01:00
/**
*
* @param generate_folders
* @returns Object un objet décrivant chaque partie des tasks.json
*/
export function get_sections_from_tasks_orgfile(generate_folders= false){
tasksList.contents.map( elem => {
let sectionTitle = elem.properties['raw-value'];
if(sectionTitle){
let cleanSectionName = removeBrackets(elem.properties['raw-value']).replace(/-*/g, "")
sectionsCleaned[cleanSectionName] = {}
if(generate_folders){
foldersGeneration(cleanSectionName);
}
console.log('section PARA: ', cleanSectionName)
elem.contents.map( content => {
let subSectionName = removeBrackets(content.properties['raw-value'])
2023-09-22 15:47:12 +02:00
console.log(' - ',subSectionName )
sectionsCleaned[cleanSectionName][subSectionName] = subSectionName
if(generate_folders){
2023-09-22 15:47:12 +02:00
foldersGeneration(`${cleanSectionName}/${subSectionName}`).then(r => {
console.log('r', r)
console.log('folders have been generated')
})
}
})
}
})
console.log('sectionsCleaned',sectionsCleaned)
return sectionsCleaned;
}
/**
* clean org tasks headings of links to roam things, remove counter cookies
* @param input
* @returns {string|*}
*/
export function removeBrackets(input) {
if(!input){
return input;
}
return input
.replace(/{.*?}/g, "")
.replace('\'', ' ')
.replace(' ', ' ')
.replace(/\[.*?\/.*?\]/g, "")
.replace(/\[\[.*?\[/g, "")
.replace(/\]*/g, "")
.replace(/<.*?>/g, "")
.replace(/\(.*?\)/g, "")
.replace(']','')
.toLowerCase()
.trim()
//.replace('[','')
;
}
get_sections_from_tasks_orgfile(true);
console.log("* Emploi du temps pour deux semaines sans inclure les weekend \n")
//displayDays();