mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
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:
@ -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;
|
||||
|
@ -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,
|
||||
);
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/widgets/markdown_toolbar.dart';
|
||||
|
Reference in New Issue
Block a user