Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions front/src/components/Dialogs/TaskExportDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ export default defineComponent({
this.onDialogCancel();
},

async downloadTaskMarkdown(task: Task) {
async downloadTaskMarkdown(task: Task, visitedUrls: string[] = []) {
const result = await fetch(task.padUrl + '/download/markdown');
if (result.status != 200) {
return `Error fetching markdown for exporting task ${task.title}`;
}
let markdown = await result.text();
if (markdown.trimStart().substring(0, 1) != '#') {
//does not start with a title, manually adding...
Expand All @@ -87,22 +90,28 @@ export default defineComponent({
}
markdown = withTitle + '\n' + markdown;
}
visitedUrls.push(task.padUrl);

// fetch subtasks recursively
const subTasks = [
...markdown.matchAll(
new RegExp(
`(https?://${window.location.host}(/pad/[a-zA-Z0-9_-]*))`,
`(https?://${window.location.host}(/pad/(?!uploads)[a-zA-Z0-9_-]*))`,
'g'
)
),
];

for (const subTask of subTasks) {
const subTaskMarkdown = await this.downloadTaskMarkdown({
...task,
padUrl: subTask[1],
});
if (visitedUrls.includes(subTask[1])) continue;

const subTaskMarkdown = await this.downloadTaskMarkdown(
{
...task,
padUrl: subTask[1],
},
visitedUrls.concat([subTask[1]])
);

markdown += `\n\n---\nContent of ${subTask[0]}\n\n${subTaskMarkdown}`;
}
Expand Down