Skip to content

Commit a76dcb4

Browse files
committed
improvements in the exported file extensions
1 parent b937380 commit a76dcb4

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/services/export/tar.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,32 @@ async function exportToTar(exportContext, branch, format, res) {
4646
}
4747

4848
function getDataFileName(note, baseFileName, existingFileNames) {
49-
let extension;
49+
const existingExtension = path.extname(baseFileName).toLowerCase();
50+
let newExtension;
5051

52+
// following two are handled specifically since we always want to have these extensions no matter the automatic detection
53+
// and/or existing detected extensions in the note name
5154
if (note.type === 'text' && format === 'markdown') {
52-
extension = 'md';
55+
newExtension = 'md';
56+
}
57+
else if (note.type === 'text' && format === 'html') {
58+
newExtension = 'html';
5359
}
5460
else if (note.mime === 'application/x-javascript' || note.mime === 'text/javascript') {
55-
extension = 'js';
61+
newExtension = 'js';
62+
}
63+
else if (existingExtension.length > 0) { // if the page already has an extension, then we'll just keep it
64+
newExtension = null;
5665
}
5766
else {
58-
extension = mimeTypes.extension(note.mime) || "dat";
67+
newExtension = mimeTypes.extension(note.mime) || "dat";
5968
}
6069

6170
let fileName = baseFileName;
62-
const existingExtension = path.extname(fileName).toLowerCase();
6371

6472
// if the note is already named with extension (e.g. "jquery.js"), then it's silly to append exact same extension again
65-
if (existingExtension !== "." + extension) {
66-
fileName += "." + extension;
73+
if (newExtension && existingExtension !== "." + newExtension.toLowerCase()) {
74+
fileName += "." + newExtension;
6775
}
6876

6977
return getUniqueFilename(existingFileNames, fileName);

0 commit comments

Comments
 (0)