Note Backlinks: Use the linkResolver

The backlinks should use the same algorithm for determining the links as
is used when clicking on a link.
This commit is contained in:
Vishesh Handa
2020-08-14 16:44:54 +02:00
parent bf97887e10
commit 2fcdfa0d6c
3 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import 'package:path/path.dart' as p;
import 'package:gitjournal/core/link.dart';
import 'package:gitjournal/core/note.dart';
class LinkResolver {
@ -7,6 +8,13 @@ class LinkResolver {
LinkResolver(this.inputNote);
Note resolveLink(Link l) {
var href = l.filePath;
href ??= '[[${l.term}]]';
return resolve(href);
}
Note resolve(String link) {
var spec = link;
var folder = inputNote.parent;

View File

@ -9,6 +9,7 @@ import 'package:gitjournal/core/note.dart';
import 'package:gitjournal/core/notes_folder_fs.dart';
import 'package:gitjournal/features.dart';
import 'package:gitjournal/folder_views/common.dart';
import 'package:gitjournal/utils/link_resolver.dart';
import 'package:gitjournal/widgets/pro_overlay.dart';
class NoteBacklinkRenderer extends StatefulWidget {
@ -39,15 +40,15 @@ class _NoteBacklinkRendererState extends State<NoteBacklinkRenderer> {
// Log.d("NoteBacklinkRenderer Predicate", props: {"filePath": n.filePath});
var links = await n.fetchLinks();
var linkResolver = LinkResolver(n);
var matchedLink = links.firstWhere(
(l) {
if (l.filePath != null) {
return l.filePath == widget.note.filePath;
var matchedNote = linkResolver.resolveLink(l);
if (matchedNote == null) {
return false;
}
var term = widget.note.pathSpec();
term = p.basenameWithoutExtension(term);
return term == l.term;
return matchedNote.filePath == widget.note.filePath;
},
orElse: () => null,
);

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:test/test.dart';
import 'package:gitjournal/widgets/markdown_toolbar.dart';