mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-03 14:06:51 +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:path/path.dart' as p;
|
||||||
|
|
||||||
|
import 'package:gitjournal/core/link.dart';
|
||||||
import 'package:gitjournal/core/note.dart';
|
import 'package:gitjournal/core/note.dart';
|
||||||
|
|
||||||
class LinkResolver {
|
class LinkResolver {
|
||||||
@ -7,6 +8,13 @@ class LinkResolver {
|
|||||||
|
|
||||||
LinkResolver(this.inputNote);
|
LinkResolver(this.inputNote);
|
||||||
|
|
||||||
|
Note resolveLink(Link l) {
|
||||||
|
var href = l.filePath;
|
||||||
|
href ??= '[[${l.term}]]';
|
||||||
|
|
||||||
|
return resolve(href);
|
||||||
|
}
|
||||||
|
|
||||||
Note resolve(String link) {
|
Note resolve(String link) {
|
||||||
var spec = link;
|
var spec = link;
|
||||||
var folder = inputNote.parent;
|
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/core/notes_folder_fs.dart';
|
||||||
import 'package:gitjournal/features.dart';
|
import 'package:gitjournal/features.dart';
|
||||||
import 'package:gitjournal/folder_views/common.dart';
|
import 'package:gitjournal/folder_views/common.dart';
|
||||||
|
import 'package:gitjournal/utils/link_resolver.dart';
|
||||||
import 'package:gitjournal/widgets/pro_overlay.dart';
|
import 'package:gitjournal/widgets/pro_overlay.dart';
|
||||||
|
|
||||||
class NoteBacklinkRenderer extends StatefulWidget {
|
class NoteBacklinkRenderer extends StatefulWidget {
|
||||||
@ -39,15 +40,15 @@ class _NoteBacklinkRendererState extends State<NoteBacklinkRenderer> {
|
|||||||
// Log.d("NoteBacklinkRenderer Predicate", props: {"filePath": n.filePath});
|
// Log.d("NoteBacklinkRenderer Predicate", props: {"filePath": n.filePath});
|
||||||
|
|
||||||
var links = await n.fetchLinks();
|
var links = await n.fetchLinks();
|
||||||
|
var linkResolver = LinkResolver(n);
|
||||||
var matchedLink = links.firstWhere(
|
var matchedLink = links.firstWhere(
|
||||||
(l) {
|
(l) {
|
||||||
if (l.filePath != null) {
|
var matchedNote = linkResolver.resolveLink(l);
|
||||||
return l.filePath == widget.note.filePath;
|
if (matchedNote == null) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var term = widget.note.pathSpec();
|
return matchedNote.filePath == widget.note.filePath;
|
||||||
term = p.basenameWithoutExtension(term);
|
|
||||||
return term == l.term;
|
|
||||||
},
|
},
|
||||||
orElse: () => null,
|
orElse: () => null,
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
import 'package:gitjournal/widgets/markdown_toolbar.dart';
|
import 'package:gitjournal/widgets/markdown_toolbar.dart';
|
||||||
|
Reference in New Issue
Block a user