Skip to content
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

Open
krisudo opened this issue Feb 29, 2024 · 5 comments
Open

Comments

@krisudo
Copy link

krisudo commented Feb 29, 2024

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:

image

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:

image
  • "Open today" works for the left sidebar
  • Command palette "Periodic Notes" commands seem to work
  • This is an empty vault (no modifications), version 1.0.5
  • Plugins bulk updated to the latest versions using the settings menu

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!

@mathisgauthey
Copy link
Owner

Hey there, I just cloned the repository on last version using these versions :

SYSTEM INFO:
	Obsidian version: v1.5.8
	Installer version: v1.4.16
	Operating system: Windows 10 Pro 10.0.22631
	Login status: logged in
	Catalyst license: none
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: AnuPpuccin v1.4.4
	Snippets enabled: 4
	Restricted mode: off
	Plugins installed: 39
	Plugins enabled: 39
		1: Style Settings v1.0.7
		2: Periodic Notes v0.0.17
		3: Omnivore v1.8.1
		4: Kanban v1.5.3
		5: Calendar v1.5.10
		6: Templater v1.16.0
		7: Commander v0.5.1
		8: Scroll to Top Plugin v2.1.3
		9: Iconize v2.6.0
		10: File Explorer Note Count v1.2.1
		11: Filename Heading Sync v1.9.0
		12: Colorful Tag v1.3.2
		13: Code Editor Shortcuts v1.14.0
		14: Find orphaned files and broken links v1.9.1
		15: Natural Language Dates v0.6.1
		16: Paste URL into selection v1.7.0
		17: Shortcuts extender v2.2.0
		18: Archiver v0.26.1
		19: Auto Link Title v1.4.1
		20: Better footnote v1.0.1
		21: Better Word Count v0.10.0
		22: Callout Manager v1.0.1
		23: Clear Unused Images v1.1.0
		24: Completr v3.2.0
		25: Dataview v0.5.64
		26: Editing Toolbar v2.4.0
		27: Footnote Shortcut v0.1.3
		28: Github Publisher v6.3.2
		29: Heatmap Calendar v0.6.0
		30: Image Toolkit v1.4.0
		31: Linter v1.20.0
		32: Note Refactor v1.8.2
		33: Paste image rename v1.6.1
		34: Show Whitespace v0.3.1
		35: Symbols Prettifier v1.1.1
		36: Tag Wrangler v0.6.1
		37: Tasks v5.5.0
		38: Todoist Plugin v1.11.1
		39: QuickAdd v1.4.0

RECOMMENDATIONS:
	Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets.
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.

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 :

  • Check if Templater has the Trigger Templater on file creation and is setup on Filename-Template file.
  • Filename heading sync plugin has Use file Open Hook disabled

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 ?

@krisudo
Copy link
Author

krisudo commented Mar 1, 2024

Hey! And thanks for the reply.

I just extracted the latest vault version and here's my starting point after updating the plugins:

SYSTEM INFO:
	Obsidian version: v1.5.8
	Installer version: v1.5.3
	Operating system: Windows 10 Enterprise 10.0.22631
	Login status: not logged in
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: AnuPpuccin v1.4.5
	Snippets enabled: 4
	Restricted mode: off
	Plugins installed: 39
	Plugins enabled: 39
		1: Periodic Notes v0.0.17
		2: Templater v2.2.1
		3: Archiver v0.26.1
		4: Auto Link Title v1.5.3
		5: Better footnote v1.0.1
		6: Better Word Count v0.10.1
		7: Calendar v1.5.10
		8: Callout Manager v1.0.1
		9: Clear Unused Images v1.1.0
		10: Code Editor Shortcuts v1.14.0
		11: Colorful Tag v1.3.2
		12: Commander v0.5.1
		13: Completr v3.2.0
		14: Dataview v0.5.64
		15: Editing Toolbar v2.4.0
		16: File Explorer Note Count v1.2.1
		17: Find orphaned files and broken links v1.9.1
		18: Footnote Shortcut v0.1.3
		19: Github Publisher v7.0.2
		20: Heatmap Calendar v0.6.0
		21: Iconize v2.10.1
		22: Image Toolkit v1.4.1
		23: Kanban v1.5.3
		24: Linter v1.23.1
		25: Natural Language Dates v0.6.2
		26: Note Refactor v1.8.2
		27: Omnivore v1.9.4
		28: Paste image rename v1.6.1
		29: Paste URL into selection v1.7.0
		30: QuickAdd v1.7.0
		31: Scroll to Top v2.1.4
		32: Shortcuts extender v2.2.0
		33: Show Whitespace v0.3.1
		34: Style Settings v1.0.7
		35: Symbols Prettifier v1.1.1
		36: Tag Wrangler v0.6.1
		37: Tasks v6.0.0
		38: Todoist Sync v1.12.0
		39: Filename Heading Sync v1.9.0

RECOMMENDATIONS:
	Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets.
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.

I started to disable plugins and with only Templater and Periodic Notes everything seem to work when clicking the link e.g. "Week 09":

SYSTEM INFO:
	Obsidian version: v1.5.8
	Installer version: v1.5.3
	Operating system: Windows 10 Enterprise 10.0.22631
	Login status: not logged in
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: AnuPpuccin v1.4.5
	Snippets enabled: 4
	Restricted mode: off
	Plugins installed: 39
	Plugins enabled: 2
		1: Templater v2.2.1
		2: Periodic Notes v0.0.17

The page gets created, has content and looks normal:

image

Then I tried to enable Filename Heading Sync and the issue is back:

SYSTEM INFO:
	Obsidian version: v1.5.8
	Installer version: v1.5.3
	Operating system: Windows 10 Enterprise 10.0.22631
	Login status: not logged in
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: AnuPpuccin v1.4.5
	Snippets enabled: 4
	Restricted mode: off
	Plugins installed: 39
	Plugins enabled: 3
		1: Templater v2.2.1
		2: Periodic Notes v0.0.17
		3: Filename Heading Sync v1.9.0

The page gets created but it's empty.

image

Here's the settings for Filename Heading Sync - I didn't touch anything:

image
And here's the default Filename-Template.md
<%*
let templater = app.plugins.plugins["templater-obsidian"];
let templateFolder = templater.settings.templates_folder;

/**
 * format:   momentjs format strings for filename
 * template: name of template
 *
 * If the file name matches the format, respective
 * template will be inserted.
 */
let 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" },
];

for (const noteType of noteTypes) {
  // If found a matching note title
  if (moment(tp.file.title, noteType.format, true).isValid()) {
    // Get TFile of template
    let templateTFile;
    try {
      // Get TFile
      templateTFile = app.vault.getAbstractFileByPath(
        `${templateFolder}/${noteType.template}`
      );

      // Error handling
      if (!templateTFile) {
        let msg =
          "Template not found\n" +
          `${templateFolder}/${noteType.template} does not exist.`;
        new Notice(msg);
        throw Error(msg);
      }
    } catch (e) {
      console.error(e);
      return;
    }

    // Insert template
    templater.templater.append_template_to_active_file(templateTFile);
    break; // Task completed, leaving the loop
  }

  // If found a matching note title
  else if (tp.file.folder(true) == noteType.format) {
    // Get TFile of template
    let templateTFile;
    try {
      // Get TFile
      templateTFile = app.vault.getAbstractFileByPath(
        `${templateFolder}/${noteType.template}`
      );

      // Error handling
      if (!templateTFile) {
        let msg =
          "Template not found\n" +
          `${templateFolder}/${noteType.template} does not exist.`;
        new Notice(msg);
        throw Error(msg);
      }
    } catch (e) {
      console.error(e);
      return;
    }

    // Insert template
    templater.templater.append_template_to_active_file(templateTFile);
    break; // Task completed, leaving the loop
  }
}
%>

I understand it's hard to debug if you cant reproduce the issue. Let me know if you spot anything weird or have any ideas what I could try next, thanks!

@mathisgauthey
Copy link
Owner

mathisgauthey commented Mar 6, 2024

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 Filename Heading Sync, Periodic Notes and Templater. I tried modifying templates as well, but couldn't come up with a solution. Sorry lad !

I updated only Templater and the issue started happening. I'd suggest creating an issue there and linking this present issue.

  • It was fine, at version 1.16.0
  • It doesn't work anymore on 2.2.3
  • The issue is linked with Filename heading sync but is independent of the template file used (I tried using template file directly and the issue is the same; even when not using the templater script
  • Maybe something to learn about tp.hooks.on_all_templates_executed ?

@mathGaki
Copy link

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.)

@mathisgauthey
Copy link
Owner

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants