mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 02:59:02 +08:00
NoteFileFormat: Refactor
Get all the allowed extensions in one place. Currently the code is scattered all over the place.
This commit is contained in:
@ -268,7 +268,7 @@ widgets:
|
|||||||
rootFolder: Root Folder
|
rootFolder: Root Folder
|
||||||
ignoredFiles:
|
ignoredFiles:
|
||||||
dot: Starts with a .
|
dot: Starts with a .
|
||||||
ext: Doesn't end with .md or .txt
|
ext: Doesn't end with one of the following -
|
||||||
drawer:
|
drawer:
|
||||||
setup: Setup Git Host
|
setup: Setup Git Host
|
||||||
pro: Unlock Pro Version
|
pro: Unlock Pro Version
|
||||||
|
@ -36,6 +36,34 @@ enum NoteType {
|
|||||||
Journal,
|
Journal,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NoteFileFormatInfo {
|
||||||
|
static List<String> allowedExtensions() {
|
||||||
|
return [
|
||||||
|
'.md',
|
||||||
|
'.txt',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static String defaultExtension(NoteFileFormat format) {
|
||||||
|
switch (format) {
|
||||||
|
case NoteFileFormat.Markdown:
|
||||||
|
return ".md";
|
||||||
|
case NoteFileFormat.Txt:
|
||||||
|
return ".txt";
|
||||||
|
default:
|
||||||
|
return ".md";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isAllowedFileName(String filePath) {
|
||||||
|
var noteFilePath = filePath.toLowerCase();
|
||||||
|
var isMarkdownFile = noteFilePath.endsWith('.md');
|
||||||
|
var isTxtFile = noteFilePath.endsWith('.txt');
|
||||||
|
|
||||||
|
return isMarkdownFile || isTxtFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum NoteFileFormat {
|
enum NoteFileFormat {
|
||||||
Markdown,
|
Markdown,
|
||||||
Txt,
|
Txt,
|
||||||
|
@ -250,13 +250,12 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
|
|||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var noteFilePath = note.filePath.toLowerCase();
|
if (!NoteFileFormatInfo.isAllowedFileName(note.filePath)) {
|
||||||
var isMarkdownFile = noteFilePath.endsWith('.md');
|
|
||||||
var isTxtFile = noteFilePath.endsWith('.txt');
|
|
||||||
if (!isMarkdownFile && !isTxtFile) {
|
|
||||||
var ignoredFile = IgnoredFile(
|
var ignoredFile = IgnoredFile(
|
||||||
filePath: fsEntity.path,
|
filePath: fsEntity.path,
|
||||||
reason: tr("ignoredFiles.ext"),
|
reason: tr("ignoredFiles.ext") +
|
||||||
|
" " +
|
||||||
|
NoteFileFormatInfo.allowedExtensions().join(' '),
|
||||||
);
|
);
|
||||||
_ignoredFiles.add(ignoredFile);
|
_ignoredFiles.add(ignoredFile);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user