Open kleutzinger opened 4 days ago
For what it's worth I've hacked together a backend js script that I run daily or manually that corrects any un-updated link text in text notes. It may not work in all cases, but it works for most things I've run into (other than internal links to attatchments like mp3).
I'll provide it here, run at your own risk; no warranty etc.
// usage: add as a JS Backend note and click 'run'
// also you can set the label #run=daily so that it runs automatically
// example link we fix:
// <a class="reference-link" href="#root/4PPhsoF84Rs6/AQYEWg4dGEfA/QVwUgibvsiXT">wrong_title</a>
const notes = api.searchForNotes(`note.type = 'text'`);
for (const bnote of notes) {
const re = new RegExp(`(<a class="reference-link"[^<]+</a>)`, "g");
const content = bnote.getContent();
let match;
while ((match = re.exec(content)) !== null) {
const hrefMatch = match[0].match(/href="([^"]+)"/);
const textMatch = match[0].match(/>([^<]+)</);
if (hrefMatch && textMatch) {
const href = hrefMatch[1];
const text = api.unescapeHtml(textMatch[1]);
const text_unescaped = textMatch[1];
const inner_id = href.split("/").pop();
const real_note = api.getNote(inner_id);
const real_title = real_note?.title;
if (real_note === undefined) {
console.log(`something weird in note ${bnote.title} - ${bnote.noteId}`);
console.log(href, text, text_unescaped, inner_id);
//todo handle:
// #root/AolpcZCFWFzk?viewMode=attachments&attachmentId=pKEPhE2EsKrr Record (online-voice-recorder.com).mp3 Record (online-voice-recorder.com).mp3 AolpcZCFWFzk?viewMode=attachments&attachmentId=pKEPhE2EsKrr
} else if (real_title !== text) {
const new_link = `<a class="reference-link" href="${href}">${real_title}</a>`;
const output_obj = {
bnote_title: bnote.title,
bnote_noteId: bnote.noteId,
old_title: text,
real_title,
time: new Date(),
};
console.log(output_obj);
// backup revision
bnote.saveRevision();
// rewrite the link inside the note's content
const newContent = content.replace(match[0], new_link);
bnote.setContent(newContent);
}
}
}
}
console.log("done running link-fixer.js");
Description
When you update the title of a note that you are internally linking to, this may not update the internal link's text in certain scenarios. The two key places I see it is in the 'view source' of the outer note doing the linking, and the content part of the outer note's share page.
It may be easier to show rather than tell, see the video or steps to recreate below.
Steps To Recreate
Observed Behavior
Expected Behavior
Potential Workarounds / Fixes
Video Example
Peek 2024-11-12 15-26-trilium-rename-bug.webm
This is a port of the issue https://github.com/zadam/trilium/issues/4879 from the original trilium project, though the same behavior can be observed on TriliumNext.
TriliumNext Version
0.90.12
What operating system are you using?
Other Linux
What is your setup?
Local + server sync
Operating System Version
Arch Linux
Error logs
No response