Skip to content

Commit 1cd2108

Browse files
01zulfithecodrr
authored andcommitted
common: include archive in export (#8279)
* common: include archive in export Signed-off-by: 01zulfi <[email protected]> * core: include archive state in md-frontmatter export Signed-off-by: 01zulfi <[email protected]>
1 parent eecb8f9 commit 1cd2108

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

apps/web/src/dialogs/settings/backup-export-settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export const BackupExportSettings: SettingsGroup[] = [
227227
if (await verifyAccount())
228228
await exportNotes(
229229
value as "txt" | "md" | "html" | "md-frontmatter",
230-
db.notes.all
230+
db.notes.exportable
231231
);
232232
}
233233
}

packages/common/src/utils/export-notes.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,21 @@ export async function* exportNotes(
7373
const notePathMap: Map<string, string[]> = new Map();
7474

7575
for await (const note of notes
76-
.fields(["notes.id", "notes.title"])
76+
.fields(["notes.id", "notes.title", "notes.archived"])
7777
.iterate()) {
7878
const filename = `${sanitizeFilename(note.title || "Untitled", {
7979
replacement: "-"
8080
})}.${FORMAT_TO_EXT[format]}`;
81+
82+
if (note.archived) {
83+
const archivePath = pathTree.add("_archive", "underscore");
84+
notePathMap.set(
85+
note.id,
86+
[archivePath].map((p) => pathTree.add(join(p, filename)))
87+
);
88+
continue;
89+
}
90+
8191
const notebooks = await database.relations
8292
.to({ id: note.id, type: "note" }, "notebook")
8393
.get();

packages/core/src/collections/notes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ export class Notes implements ICollection {
251251
);
252252
}
253253

254+
get exportable() {
255+
return this.collection.createFilter<Note>(
256+
(qb) => qb.where(isFalse("dateDeleted")).where(isFalse("deleted")),
257+
this.db.options?.batchSize
258+
);
259+
}
260+
254261
// isTrashed(id: string) {
255262
// return this.raw.find((item) => item.id === id && isTrashItem(item));
256263
// }

packages/core/src/utils/templates/md.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function buildFrontmatter(data: TemplateData) {
4040
];
4141
if (data.pinned) lines.push(`pinned: ${data.pinned}`);
4242
if (data.favorite) lines.push(`favorite: ${data.favorite}`);
43+
if (data.archived) lines.push(`archived: ${data.archived}`);
4344
if (data.color) lines.push(`color: ${data.color}`);
4445
if (data.tags) lines.push(`tags: ${data.tags.join(", ")}`);
4546
return lines.join("\n");

0 commit comments

Comments
 (0)