Home > Reflections | โฎ๏ธ โญ๏ธ
2024-11-23 | ๐ Template ๐ค Automation
โ Improving My Reflection Template
๐ผ๏ธ Context
- โ๏ธ I Blog From Obsidian
- ๐ค I automate the creation of reflections with Templater.
- ๐ฟ But my process isnโt fully automated.
- ๐๐จ๐ฅต I manually update the โฎ๏ธ link.
- ๐๐น๏ธ๐ฅต And I semi-manually add the โญ๏ธ link to the previous reflection.
- ๐ข๐ข I want to blog more.
- ๐ฅงโ 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
- โฎ๏ธ Insert the link to the previous reflection
- โญ๏ธ 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
- ๐ค Chat bots help.
- ๐ง Theyโre not perfect.
- ๐ But with good prompts, some patience, and iteration, they can dramatically speed up writing (code or otherwise) by quickly generating pretty good drafts.
- :) I โค๏ธ emojis.
- ๐ค I โค๏ธ automation.
- ๐ฅง Easier โ โ More
- ๐ฃ I โค๏ธ Blogging.
- ๐ฅณ Iโm having fun.
๐งโ๐ Exploring Quartz Features
- Free RSS feed and sitemap
- ๐ฌ Giscus Comments?!
- ๐คฏ Did Quartz do this before or after I did?
- ๐คฏ Obsidian and Quartz support YouTube video embeds via markdown image syntax!
- Iโve been planning to eventually go through my video pages and figure out how to embed the YouTube video in the page.
- Now itโs super easy.
- Check it out: Parables on the Power of Planning in AI: From Poker to Diplomacy: Noam Brown (OpenAI)
๐ง 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.
- ๐ What do you think?
- โ๏ธ Have you found practical or entertainment value in anything Iโve written?
- ๐ช๐ช Do you have any advice?
- ๐ฌ 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).