-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Bug report) Renaming a Note Doesn't Update Link Text on Internal Links on Share Page #672
Labels
bug
Something isn't working
Comments
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">title</a>
// you'll have to create a text note somewhere and put its ID here
// it will log what changes we make to a note. If this note doesn't exist, we don't log.
const log_note_id = "wtiffFWxDFar";
console.log("running link-fixer.js");
function note2title(b_note) {
return `${b_note?.noteId} - ${b_note?.title}`;
}
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 observed_title_raw = textMatch[1];
const observed_title_text = api.unescapeHtml(observed_title_raw);
const inner_id = href.split("/").pop();
const real_note = api.getNote(inner_id);
const real_title = real_note?.title;
if (real_note?.isProtected) {
// the link is to a protected note don't modify it
console.log("dont modify link to protected note " + note2title(real_note))
continue;
}
if (real_note === undefined) {
console.log(`something weird in note ${bnote.title} - ${bnote.noteId}`);
console.log(href, observed_title_text, observed_title_raw, 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 !== observed_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: observed_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);
const logNote = api.getNote(log_note_id);
if (logNote) {
logNote.setContent(
`<p><code>${JSON.stringify(output_obj, null, 2)}</code></p>${logNote.getContent()}`,
{ forceSave: true },
);
console.log("wrote to " + note2title(logNote));
} else {
console.log("no log note found with id " + log_note_id);
}
}
}
}
}
console.log("done running link-fixer.js"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 zadam/trilium#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
The text was updated successfully, but these errors were encountered: