mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
export WIP + some unrelated changes
This commit is contained in:
parent
e09b61d1ac
commit
551e1255ff
@ -0,0 +1 @@
|
|||||||
|
UPDATE attributes SET name = 'archived' where name = 'hideInAutocomplete';
|
@ -695,3 +695,7 @@ div[data-notify="container"] {
|
|||||||
padding-left: 40px;
|
padding-left: 40px;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#export-form .form-check-label {
|
||||||
|
padding: 2px;
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
const build = require('./build');
|
const build = require('./build');
|
||||||
const packageJson = require('../../package');
|
const packageJson = require('../../package');
|
||||||
|
|
||||||
const APP_DB_VERSION = 119;
|
const APP_DB_VERSION = 120;
|
||||||
const SYNC_VERSION = 2;
|
const SYNC_VERSION = 2;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -12,17 +12,24 @@ const TurndownService = require('turndown');
|
|||||||
async function exportToTar(branch, format, res) {
|
async function exportToTar(branch, format, res) {
|
||||||
const turndownService = new TurndownService();
|
const turndownService = new TurndownService();
|
||||||
|
|
||||||
|
// path -> number of occurences
|
||||||
|
const existingPaths = {};
|
||||||
|
|
||||||
const pack = tar.pack();
|
const pack = tar.pack();
|
||||||
|
|
||||||
const exportedNoteIds = [];
|
const exportedNoteIds = [];
|
||||||
const name = await exportNoteInner(branch, '');
|
const name = await exportNoteInner(branch, '');
|
||||||
|
|
||||||
async function exportNoteInner(branch, directory) {
|
function getUniqueFilename(fileName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function exportNoteInner(branch, directory, existingNames) {
|
||||||
const note = await branch.getNote();
|
const note = await branch.getNote();
|
||||||
const childFileName = directory + sanitize(note.title);
|
const baseFileName = directory + sanitize(note.title);
|
||||||
|
|
||||||
if (exportedNoteIds.includes(note.noteId)) {
|
if (exportedNoteIds.includes(note.noteId)) {
|
||||||
saveMetadataFile(childFileName, {
|
saveMetadataFile(baseFileName, {
|
||||||
version: 1,
|
version: 1,
|
||||||
clone: true,
|
clone: true,
|
||||||
noteId: note.noteId,
|
noteId: note.noteId,
|
||||||
@ -67,26 +74,27 @@ async function exportToTar(branch, format, res) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveMetadataFile(childFileName, metadata);
|
saveMetadataFile(baseFileName, metadata);
|
||||||
saveDataFile(childFileName, note);
|
saveDataFile(baseFileName, note);
|
||||||
|
|
||||||
exportedNoteIds.push(note.noteId);
|
exportedNoteIds.push(note.noteId);
|
||||||
|
|
||||||
const childBranches = await note.getChildBranches();
|
const childBranches = await note.getChildBranches();
|
||||||
|
|
||||||
if (childBranches.length > 0) {
|
if (childBranches.length > 0) {
|
||||||
saveDirectory(childFileName);
|
saveDirectory(baseFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const childBranch of childBranches) {
|
for (const childBranch of childBranches) {
|
||||||
await exportNoteInner(await childBranch.getNote(), childBranch, childFileName + "/");
|
await exportNoteInner(childBranch, baseFileName + "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
return childFileName;
|
return baseFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveDataFile(childFileName, note) {
|
function saveDataFile(childFileName, note) {
|
||||||
let content = note.content;
|
let content = note.content;
|
||||||
|
let extension;
|
||||||
|
|
||||||
if (note.type === 'text') {
|
if (note.type === 'text') {
|
||||||
if (format === 'html') {
|
if (format === 'html') {
|
||||||
@ -94,15 +102,18 @@ async function exportToTar(branch, format, res) {
|
|||||||
}
|
}
|
||||||
else if (format === 'markdown') {
|
else if (format === 'markdown') {
|
||||||
content = turndownService.turndown(note.content);
|
content = turndownService.turndown(note.content);
|
||||||
|
extension = 'md';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error("Unknown format: " + format);
|
throw new Error("Unknown format: " + format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const extension = mimeTypes.extension(note.mime)
|
if (!extension) {
|
||||||
|
extension = mimeTypes.extension(note.mime)
|
||||||
|| getExceptionalExtension(note.mime)
|
|| getExceptionalExtension(note.mime)
|
||||||
|| "dat";
|
|| "dat";
|
||||||
|
}
|
||||||
|
|
||||||
if (!childFileName.toLowerCase().endsWith(extension)) {
|
if (!childFileName.toLowerCase().endsWith(extension)) {
|
||||||
childFileName += "." + extension;
|
childFileName += "." + extension;
|
||||||
@ -117,14 +128,14 @@ async function exportToTar(branch, format, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveMetadataFile(childFileName, metadata) {
|
function saveMetadataFile(baseFileName, metadata) {
|
||||||
const metadataJson = JSON.stringify(metadata, null, '\t');
|
const metadataJson = JSON.stringify(metadata, null, '\t');
|
||||||
|
|
||||||
pack.entry({name: childFileName + ".meta", size: metadataJson.length}, metadataJson);
|
pack.entry({name: getUniqueFilename(baseFileName + ".meta"), size: metadataJson.length}, metadataJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveDirectory(childFileName) {
|
function saveDirectory(baseFileName) {
|
||||||
pack.entry({name: childFileName, type: 'directory'});
|
pack.entry({name: baseFileName, type: 'directory'});
|
||||||
}
|
}
|
||||||
|
|
||||||
pack.finalize();
|
pack.finalize();
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
<a id="collapse-tree-button" title="Collapse note tree. Shortcut ALT+C" class="icon-action jam jam-align-justify"></a>
|
<a id="collapse-tree-button" title="Collapse note tree. Shortcut ALT+C" class="icon-action jam jam-align-justify"></a>
|
||||||
|
|
||||||
<a id="scroll-to-current-note-button" title="Scroll to current note. Shortcut CTRL+." class="icon-action jam jam-target"></a>
|
<a id="scroll-to-current-note-button" title="Scroll to current note. Shortcut CTRL+." class="icon-action jam jam-download"></a>
|
||||||
|
|
||||||
<a id="toggle-search-button" title="Search in notes. Shortcut CTRL+S" class="icon-action jam jam-search"></a>
|
<a id="toggle-search-button" title="Search in notes. Shortcut CTRL+S" class="icon-action jam jam-search"></a>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user