-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
2024-02-29 Issues with Daily-Note navigation links after plugin update #9
Comments
Hey there, I just cloned the repository on last version using these versions :
I can't reproduce the issue on a freshly cloned vault with the last Obsidian version, I probably won't be able to help more now. But I'd suggest to :
Maybe try to disable every plugin except Templater and Periodic Note ? If it works, then a plugin is causing the issue. So try by activating half, and then another half using a divide and conquer strategy to find the potential plugin that causes the issue ? |
Alright, thanks for the detailed message. I was able to reproduce by updating all plugins. I'm looking for a fix right now, I'll keep you updated here. Edit : I'm sorry, I tried for the last hour or so, and did not find any solution. I'm sure it is between I updated only
|
Hello! I've found a solution for the template application error occurring in the latest version of Templater. The issue seems to arise from the concurrent execution of 1. template application and 2. file movement. So I tried to clearly separate these two steps. Here's the example code: [Filename-Template.md] <%*
let templater = app.plugins.plugins["templater-obsidian"];
let templateFolder = templater.settings.templates_folder;
// Template configurations
const noteTypes = [
{ format: "YYYY-MM-DD", template: "Daily-Notes.md" },
{ format: "GGGG-[W]WW", template: "Weekly-Notes.md" },
{ format: "YYYY-MM", template: "Monthly-Notes.md" },
{ format: "YYYY-[Q]Q", template: "Quarterly-Notes.md" },
{ format: "YYYY", template: "Yearly-Notes.md" },
{ format: "2-Areas", template: "Areas.md" },
{ format: "0-Inbox", template: "Untitled.md" },
];
// Helper function to get template file
async function getTemplateFile(templatePath) {
const templateFile = app.vault.getAbstractFileByPath(templatePath);
if (!templateFile) {
const msg = `Template not found: ${templatePath} does not exist.`;
new Notice(msg);
throw new Error(msg);
}
return templateFile;
}
// Helper function to check if note matches format
function isMatchingNote(noteTitle, format) {
return moment(noteTitle, format, true).isValid() || tp.file.folder(true) === format;
}
// Main function to process template
async function processTemplate() {
try {
for (const noteType of noteTypes) {
if (isMatchingNote(tp.file.title, noteType.format)) {
const templatePath = `${templateFolder}/${noteType.template}`;
const templateFile = await getTemplateFile(templatePath);
await templater.templater.append_template_to_active_file(templateFile);
return; // Exit after successful template insertion
}
}
} catch (error) {
console.error('Template processing failed:', error);
new Notice(`Template processing failed: ${error.message}`);
}
}
// Execute
await processTemplate();
%>` [Daily Notes.md] <%*
async function applyTemplate() {
try {
// 1. Validate the date format
const currentMoment = moment(tp.file.title, "YYYY-MM-DD", true);
if (!currentMoment.isValid()) {
new Notice("Invalid date format. Expected YYYY-MM-DD");
return "";
}
// 2. Add initial delay before file movement
await new Promise(resolve => setTimeout(resolve, 300));
// 3. Move the file to target location
const targetPath = "/-Daily-Notes/" + tp.file.title;
await tp.file.move(targetPath);
// 4. Wait for file movement to complete
await new Promise(resolve => setTimeout(resolve, 300));
// 5. Generate template content
let content = "";
// Main date header
content += "# " + currentMoment.format("YYYY-MM-DD") + "\n";
// Hierarchical navigation
content += "❮ ";
content += "[[" + currentMoment.format("YYYY") + "]]" + " / ";
content += "[[" + currentMoment.format("YYYY-[Q]Q|[Q]Q") + "]]" + " / ";
content += "[[" + currentMoment.format("YYYY-MM|MMMM") + "]]" + " / ";
content += "[[" + currentMoment.format("GGGG-[W]WW|[Week] WW") + "]]";
content += " ❯\n\n";
// Day navigation
content += "❮ ";
content += "[[" + moment(currentMoment).subtract(1, "days").format("YYYY-MM-DD|dddd Do") + "]]" + " | ";
content += currentMoment.format("dddd Do") + " | ";
content += "[[" + moment(currentMoment).add(1, "days").format("YYYY-MM-DD|dddd Do") + "]]";
content += " ❯\n\n";
// Tasks sections
content += `> [!CHECK]+ Super Productivity ☑️
>
> \`\`\`tasks
> not done
> (happens on or before 2024-07-30) OR (status.type is IN_PROGRESS)
> (heading does not include Focus) AND (heading does not include Goals)
> group by function (task.isRecurring) ? '%%3%% Recurring Tasks' : result = task.description.includes("[[") ? '%%1%% Projects' : '%%2%% Tasks'
> \`\`\`
> [!IMPORTANT]+ Short Next Actions 🏃
>
> \`\`\`tasks
> not done
> is not recurring
> description does not include ]]
> tags include #next
> group by function task.tags.filter( (tag) => tag.includes("#next") )
> short mode
> \`\`\`\n`;
// Notes section
content += "## Notes 📝\n";
// 6. Add final delay before content application
await new Promise(resolve => setTimeout(resolve, 300));
return content;
} catch (error) {
console.error("Template Error:", error);
new Notice(`Template Error: ${error.message}`);
return "";
}
}
// Execute the template
tR = await applyTemplate();
%> (The example templates might slightly differ from your original templates.) While this approach makes the template application slightly slower, it seems to work stably even in the latest version of Templater (version 2.9.0 in my case). (P.S. I've been using your Obsidian workflow with great satisfaction. Thank you for sharing it with the community.) |
Hey there, thanks for the correction, feel free to submit a PR to review and I'll add it to the next version of the workflow ! I'm glad my work helped you somehow, thanks for your kind words ! |
Hi @mathisgauthey!
And thanks for the template. I've been testing it out for few days and it feels great for my use case. I was just about to migrate fully, but after I updated the plugins today I'm experiencing issues with the Daily-Note navigation links e.g. these:
When clicking any of the links (2024/Q1/February/Week 09) It creates a page and the template quickly flashes/shows but after that it's an empty page:
Any ideas how to fix and what could cause this? I'd like to start using the template and this functionality is handy on the daily note.
Thanks!
The text was updated successfully, but these errors were encountered: