1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 10:46:32 +00:00

- export untitled notes as 'Untitled' based on the language

- export notes with duplicate title as '<title> (<index>)'
This commit is contained in:
Baptiste Augrain
2020-06-12 16:18:27 +02:00
parent 5414fe3384
commit 80b8948433
6 changed files with 57 additions and 14 deletions

View File

@@ -0,0 +1,37 @@
import filenamify from 'filenamify'
import i18n from 'browser/lib/i18n'
import path from 'path'
/**
* @param {Object} note
* @param {String} fileType
* @param {String} directory
* @param {Object} deduplicator
*
* @return {String}
*/
function getFilename(note, fileType, directory, deduplicator) {
const basename = note.title
? filenamify(note.title, { replacement: '_' })
: i18n.__('Untitled')
if (deduplicator) {
if (deduplicator[basename]) {
const filename = path.join(
directory,
`${basename} (${deduplicator[basename]}).${fileType}`
)
++deduplicator[basename]
return filename
} else {
deduplicator[basename] = 1
}
}
return path.join(directory, `${basename}.${fileType}`)
}
module.exports = getFilename