mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
Setting: Note metadata change subtitle
This commit is contained in:
@ -39,7 +39,7 @@ settings:
|
|||||||
subtitle: Configure where your notes are synced
|
subtitle: Configure where your notes are synced
|
||||||
noteMetaData:
|
noteMetaData:
|
||||||
title: Note Metadata Settings
|
title: Note Metadata Settings
|
||||||
subtitle: Configure how the YAML Metadata is saved
|
subtitle: Configure how the Note Metadata is saved
|
||||||
text: Every note has some metadata which is stored in a YAML Header as follows -
|
text: Every note has some metadata which is stored in a YAML Header as follows -
|
||||||
enableHeader: Enable YAML Header
|
enableHeader: Enable YAML Header
|
||||||
modified: Modified Field
|
modified: Modified Field
|
||||||
|
@ -50,6 +50,7 @@ class NoteSerializer implements NoteSerializerInterface {
|
|||||||
if (settings.saveTitleAsH1) {
|
if (settings.saveTitleAsH1) {
|
||||||
if (title.isNotEmpty) {
|
if (title.isNotEmpty) {
|
||||||
data.body = '# $title\n\n${data.body}';
|
data.body = '# $title\n\n${data.body}';
|
||||||
|
data.props.remove(settings.titleKey);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (title.isNotEmpty) {
|
if (title.isNotEmpty) {
|
||||||
@ -102,8 +103,10 @@ class NoteSerializer implements NoteSerializerInterface {
|
|||||||
//
|
//
|
||||||
// Title parsing
|
// Title parsing
|
||||||
//
|
//
|
||||||
if (settings.saveTitleAsH1) {
|
if (data.props.containsKey(settings.titleKey)) {
|
||||||
if (note.body.startsWith('#')) {
|
var title = data.props[settings.titleKey]?.toString() ?? "";
|
||||||
|
note.title = emojiParser.emojify(title);
|
||||||
|
} else if (note.body.startsWith('#')) {
|
||||||
var titleEndIndex = note.body.indexOf('\n');
|
var titleEndIndex = note.body.indexOf('\n');
|
||||||
if (titleEndIndex == -1 || titleEndIndex == note.body.length) {
|
if (titleEndIndex == -1 || titleEndIndex == note.body.length) {
|
||||||
note.title = note.body.substring(1).trim();
|
note.title = note.body.substring(1).trim();
|
||||||
@ -112,15 +115,13 @@ class NoteSerializer implements NoteSerializerInterface {
|
|||||||
note.title = note.body.substring(1, titleEndIndex).trim();
|
note.title = note.body.substring(1, titleEndIndex).trim();
|
||||||
note.body = note.body.substring(titleEndIndex + 1).trim();
|
note.body = note.body.substring(titleEndIndex + 1).trim();
|
||||||
}
|
}
|
||||||
}
|
/*
|
||||||
for (var line in LineSplitter.split(note.body)) {
|
for (var line in LineSplitter.split(note.body)) {
|
||||||
if (note.title.isEmpty && line.trim().isEmpty) {
|
if (note.title.isEmpty && line.trim().isEmpty) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
*/
|
||||||
var title = data.props[settings.titleKey]?.toString() ?? "";
|
|
||||||
note.title = emojiParser.emojify(title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = data.props[settings.typeKey];
|
var type = data.props[settings.typeKey];
|
||||||
|
@ -30,7 +30,7 @@ void main() {
|
|||||||
expect(doc.props['title'].toString(), "I :heart: you");
|
expect(doc.props['title'].toString(), "I :heart: you");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test Title', () {
|
test('Test Title Serialization', () {
|
||||||
var props = <String, dynamic>{};
|
var props = <String, dynamic>{};
|
||||||
var doc = MdYamlDoc("# Why not :coffee:?\n\nI :heart: you", props);
|
var doc = MdYamlDoc("# Why not :coffee:?\n\nI :heart: you", props);
|
||||||
|
|
||||||
@ -50,5 +50,24 @@ void main() {
|
|||||||
expect(doc.body, "# I :heart: you\n\nWhy not :coffee:?");
|
expect(doc.body, "# I :heart: you\n\nWhy not :coffee:?");
|
||||||
expect(doc.props.length, 0);
|
expect(doc.props.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test Old Title Serialization', () {
|
||||||
|
var props = LinkedHashMap<String, dynamic>.from(
|
||||||
|
<String, dynamic>{"title": "Why not :coffee:?"});
|
||||||
|
var doc = MdYamlDoc("I :heart: you", props);
|
||||||
|
|
||||||
|
var serializer = NoteSerializer();
|
||||||
|
serializer.settings.saveTitleAsH1 = true;
|
||||||
|
|
||||||
|
var note = Note(null, "file-path-not-important");
|
||||||
|
serializer.decode(doc, note);
|
||||||
|
|
||||||
|
expect(note.body, "I ❤️ you");
|
||||||
|
expect(note.title, "Why not ☕?");
|
||||||
|
|
||||||
|
serializer.encode(note, doc);
|
||||||
|
expect(doc.body, "# Why not :coffee:?\n\nI :heart: you");
|
||||||
|
expect(doc.props.length, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user