Home > Reflections | โฎ๏ธ โญ๏ธ

2024-11-23 | ๐Ÿ“‘ Template ๐Ÿค– Automation

โž• 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).