Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

common: include archive in export (#8279)

01zulfi1cd21087c21e
diff --git a/apps/web/src/dialogs/settings/backup-export-settings.ts b/apps/web/src/dialogs/settings/backup-export-settings.ts
index 4709f1ecf..5b009bde1 100644
--- a/apps/web/src/dialogs/settings/backup-export-settings.ts
+++ b/apps/web/src/dialogs/settings/backup-export-settings.ts
@@ -227,7 +227,7 @@ export const BackupExportSettings: SettingsGroup[] = [
if (await verifyAccount())
await exportNotes(
value as "txt" | "md" | "html" | "md-frontmatter",
- db.notes.all
+ db.notes.exportable
);
}
}
diff --git a/packages/common/src/utils/export-notes.ts b/packages/common/src/utils/export-notes.ts
index 97bea607e..fe0e55f58 100644
--- a/packages/common/src/utils/export-notes.ts
+++ b/packages/common/src/utils/export-notes.ts
@@ -73,11 +73,21 @@ export async function* exportNotes(
const notePathMap: Map<string, string[]> = new Map();
for await (const note of notes
- .fields(["notes.id", "notes.title"])
+ .fields(["notes.id", "notes.title", "notes.archived"])
.iterate()) {
const filename = `${sanitizeFilename(note.title || "Untitled", {
replacement: "-"
})}.${FORMAT_TO_EXT[format]}`;
+
+ if (note.archived) {
+ const archivePath = pathTree.add("_archive", "underscore");
+ notePathMap.set(
+ note.id,
+ [archivePath].map((p) => pathTree.add(join(p, filename)))
+ );
+ continue;
+ }
+
const notebooks = await database.relations
.to({ id: note.id, type: "note" }, "notebook")
.get();
diff --git a/packages/core/src/collections/notes.ts b/packages/core/src/collections/notes.ts
index a63ba4e4a..7dd58198e 100644
--- a/packages/core/src/collections/notes.ts
+++ b/packages/core/src/collections/notes.ts
@@ -251,6 +251,13 @@ export class Notes implements ICollection {
);
}
+ get exportable() {
+ return this.collection.createFilter<Note>(
+ (qb) => qb.where(isFalse("dateDeleted")).where(isFalse("deleted")),
+ this.db.options?.batchSize
+ );
+ }
+
// isTrashed(id: string) {
// return this.raw.find((item) => item.id === id && isTrashItem(item));
// }
diff --git a/packages/core/src/utils/templates/md.ts b/packages/core/src/utils/templates/md.ts
index 7bc1f52c0..5b096a6c5 100644
--- a/packages/core/src/utils/templates/md.ts
+++ b/packages/core/src/utils/templates/md.ts
@@ -40,6 +40,7 @@ function buildFrontmatter(data: TemplateData) {
];
if (data.pinned) lines.push(`pinned: ${data.pinned}`);
if (data.favorite) lines.push(`favorite: ${data.favorite}`);
+ if (data.archived) lines.push(`archived: ${data.archived}`);
if (data.color) lines.push(`color: ${data.color}`);
if (data.tags) lines.push(`tags: ${data.tags.join(", ")}`);
return lines.join("\n");