mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +08:00
WikiLinks: Always resolve from the base path
Fixes #212 With this [[Fire]] will always resolve the rootFolder/Fire.md irrespective of which note it appears in. This is analogous to the way Obsidian works.
This commit is contained in:
@ -7,7 +7,7 @@ class LinkResolver {
|
||||
|
||||
Note resolve(String link) {
|
||||
var spec = link;
|
||||
var parent = inputNote.parent;
|
||||
var rootFolder = inputNote.parent.rootFolder;
|
||||
|
||||
if (link.startsWith('[[') && link.endsWith(']]') && link.length > 4) {
|
||||
// FIXME: What if the case is different?
|
||||
@ -18,20 +18,20 @@ class LinkResolver {
|
||||
spec = link.substring(2);
|
||||
}
|
||||
|
||||
var linkedNote = parent.getNoteWithSpec(spec);
|
||||
var linkedNote = rootFolder.getNoteWithSpec(spec);
|
||||
if (linkedNote != null) {
|
||||
return linkedNote;
|
||||
}
|
||||
|
||||
if (!spec.endsWith('.md')) {
|
||||
linkedNote = parent.getNoteWithSpec(spec + '.md');
|
||||
linkedNote = rootFolder.getNoteWithSpec(spec + '.md');
|
||||
if (linkedNote != null) {
|
||||
return linkedNote;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spec.endsWith('.txt')) {
|
||||
linkedNote = parent.getNoteWithSpec(spec + '.txt');
|
||||
linkedNote = rootFolder.getNoteWithSpec(spec + '.txt');
|
||||
if (linkedNote != null) {
|
||||
return linkedNote;
|
||||
}
|
||||
|
@ -75,6 +75,14 @@ void main() {
|
||||
var resolvedNote = linkResolver.resolve('[[zeplin]]');
|
||||
expect(resolvedNote.filePath, p.join(tempDir.path, 'zeplin.txt'));
|
||||
});
|
||||
|
||||
test('Non base path [[Fire]] should resolve to [[Fire.md]]', () {
|
||||
var note = rootFolder.getNoteWithSpec('Folder/Water.md');
|
||||
var linkResolver = LinkResolver(note);
|
||||
|
||||
var resolvedNote = linkResolver.resolve('[[Fire]]');
|
||||
expect(resolvedNote.filePath, p.join(tempDir.path, 'Fire.md'));
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> generateNote(String basePath, String path) async {
|
||||
|
Reference in New Issue
Block a user