Home > Reflections | ⏮️ ⏭️

2024-11-23

➕ Improving My Reflection Template

🖼️ Context

  1. ✍️ I Blog From Obsidian
  2. 🤖 I automate the creation of reflections with Templater.
  3. 😿 But my process isn’t fully automated.
    1. 🔗🔨🥵 I manually update the ⏮️ link.
    2. 🔗🕹️🥵 And I semi-manually add the ⏭️ link to the previous reflection.
  4. 📢📢 I want to blog more.
  5. 🥧✅ Theory: (all else equal) the easier it is, the more often I’ll do it. See the Tiny Habits Behavior Model.

🎯 Goal

✍️🤖 Streamline blogging.

📐 Specification

🔧 Update my reflection template to

  1. ⏮️ Insert the link to the previous reflection
  2. ⏭️ Insert the link to this reflection in the previous reflection

🪜 Steps

1) 🤖 ChatGPT

🗣️❓🤖 Initial Prompt

I have an obsidian templater template to create a file in a folder.
Each file in this folder is named after the current date: YYYY-MM-DD.
I want to update the template to include a link to the most recent file.
Can you write me a snippet of templater code to do this?

🤖💬🤔 Initial Response (Sans Explanation)

⚠️ Warning: this code is slightly broken

<%*  
const folderPath = 'your/folder/path'; // Replace with the path to your folder  
const today = tp.date.now("YYYY-MM-DD");  
const files = app.vault.getFiles();  
const recentFile = files  
  .filter(file => file.path.startsWith(folderPath) && file.name <= today)  
  .sort((a, b) => b.name.localeCompare(a.name))[0]; // Get the most recent file  
const link = recentFile ? `[[${recentFile.name}]]` : "No recent file found"; // Create link  
link  
%>  

2) 🔧Modify ▶️👀Test ♻️Repeat

The first snippet didn’t work.
ChatGPT and I fixed errors and iterated.

flowchart  
    subgraph Loop [ ];  
        R("▶️ Run Template") --> F("🐛👀 Failure") --> C("🔧 Change Code") --> R  
    end  
  
    R --> S("💰👀 Success")  
  
style Loop fill:none, stroke:none  

📜 Result

My reflection template now automatically creates a previous link pointing to the most recent reflection and modifies that reflection to link to the new one! 🎉🤖🥂🥳

[[index|Home]] > [[reflections/index|Reflections]] | <%*  
const folderPath = 'reflections'  
const today = tp.date.now("YYYY-MM-DD")  
const files = app.vault.getFiles()  
const recentFile = files  
  .filter(file => file.path.startsWith(folderPath) && file.name <= today)  
  .sort((a, b) => b.name.localeCompare(a.name))[0]  
  
const stripExtension = p => p.replace(/\.[^.]+$/, '')  
  
if (recentFile) {  
  const recentFilePath = stripExtension(recentFile.path)  
  const currentFilePath = recentFilePath.replace(/\d{4}(-\d{2}){2}/, today)  
  tR += `[[${recentFilePath}|⏮️]]`  
  const recentFileContent = await app.vault.read(recentFile)  
  const nextLink = `⏮️]] [[${currentFilePath}|⏭️]]`  
  const updatedContent = recentFileContent.replace('⏮️]]', nextLink)  
  await app.vault.modify(recentFile, updatedContent)  
} else {  
  tR += "No recent file found"  
}  
%>  

🪞 Reflections

  1. 🤖 Chat bots help.
    1. 🧐 They’re not perfect.
    2. 🚄 But with good prompts, some patience, and iteration, they can dramatically speed up writing (code or otherwise) by quickly generating pretty good drafts.
  2. :) I ❤️ emojis.
  3. 🤖 I ❤️ automation.
    1. 🥧 Easier ✅ More
  4. 📣 I ❤️ Blogging.
    1. 🥳 I’m having fun.

🧑‍🚀 Exploring Quartz Features

🧜 Troubleshooting Mermaid

  • 🤔 the graph on this page renders in Obsidian but not on my website.
    • 🐛 on my site: syntax error, version 10.7.0
  • 🤞 let’s try upgrading mermaidjs to the latest version: 11.4.0
  • 🤔 nope… Same error, different version
  • 💰 There we go…
    • 🚛 adding a semicolon after the end bracket fixed it
    • ⬜ I think some compilation step added whitespace after the square bracket and broke the parser
    • ❗ I guess punctuation can be important

⚡ Tuning the Build

  • Is 1 - 2 minutes too long to wait for my blog posts to publish? Yes. Let’s
    • only checkout the latest commit,
    • cache npm dependencies,
    • combine jobs,
    • update GitHub actions,
    • reduce polling frequency,
    • use smaller containers with node pre-installed.
  • Here’s the GitHub workflow file before and after.
  • We went from typically 1 - 2 minutes to typically 30 - 40 seconds.
    • Most of the time spent over 30 seconds is waiting for a runner.
    • Previously, most of the time spent over 1 minute was spent waiting for runners.
    • So we basically cut our build time in half.
  • Not bad!
    • Of course, 30 seconds per build will never pay back the time I spent optimizing.
    • But speed is a virtue.
      • Lightning fast builds make it easy and rewarding to change often.
      • The ability to make very frequent changes allows for rapid iteration cycles that wouldn’t be practical otherwise.
      • And perhaps I’m good at rationalizing my own behavior to avoid regret.
  • Potential for future improvement:
    • reduce dependencies to minimize cache download time
    • cache generated html and quartz build incrementally to avoid unnecessary rework.

📥 Invitation

I recently added comments to this site.

  1. 👂 What do you think?
  2. ⚖️ Have you found practical or entertainment value in anything I’ve written?
  3. 🪙🪙 Do you have any advice?
  4. 💬 If you have a GitHub account, let me know what you think by leaving a comment below (or how you feel by leaving an emoji reaction for this page).