Implementing continuous Flag in Lazydraft
This is Part 5 in Building a CLI in Rust Series
I recently saw Kepano’s tweet where he announced the webViewer is coming to Obsidian, the tool I use for almost all of my note-taking. This was a great opportunity for me to finally add the feature I was dreading to add to lazydraft: --watch
style continous stage mode where my local website would be updated constantly as I write.
I’ve tried something different this time. I decided to implement this feature fully using LLM’s and test their capabilities.
—continous Flag
The basic idea for continuously updating the draft I am writing is to create a watcher, attaching to the directory, and according to the changes, re-transfer the latest version of the draft and all of the related content. So It has to know the other used methods as well. ChatGPT offered a similar solution like this.
We first create a watcher, and start to watch the source directory.
Then when the received event is a modification, we create the writing list using the config, find the modified writing, check if it is in a draft state or not, and update everything related to that writing.
Code could certainly be optimized but we are checking every 2 seconds, and for my usecase it is more than enough. Updates are instantaneous and I can immediately see what the article would look like on my website.
I though about changing the structure of the tool so that the default approach would be continous staging as it is. But both options have their own usecases. So I decided to add this as a flag to the stage
command.
Here is my current workflow
Updating CI
After tackling this and realized that I forgot both how to release a new version, and serve a binary through Homebrew, I decided to upgrade its release pipeline and some extra.
To publish a brew formula, you have to have a seperate repository where you define your formulaes.
Previously I released a new version using Github Actions and manually copy paste the binary information to the formulae page. Using ChatGPT, I created these additional steps where I
- Compute the SHA256 of the created binary
- Clone my Formulae repository for updating
- Change every related information inside the formulate to automatically publish a new release.
Here are the added steps, they can be tweaked for a similar setup
Now all I have to do is to implement the feature, add a tag to the end for the new version and push the changes. Everything is automatic. This was something I should have done a long time ago. Using LLM’s reduces the friction to start, you can just ask things and estimate how long it’s going to take.
Additional Improvements
Looking at the source code of lazydraft, I realized that I haven’t been using the feature I wanted to add so long. Adding automatic cover to the posts. Seeing that, I also implemented the same process for og image creation. By implementing these two functions, I no longer need to define a path which was the thing that annoyed me the most.
There is also a config command available for lazydraft, but since opening the config is saved on my local machine, I continously postphoned that feature as well. Running the lazydradt for the very first time creates the config ready to be updated. Now, config
command opens the config file with your editor of choice:
And lastly, what this tool does was really ambiguous to everyone except me. I used development version on my machine without pushing a new feature or fixing that bug. You can also forget the commands of your own tool if you don’t use it long enough. That is my fault though. Still, I needed to add a simple explanatory info for lazydraft
, one I won’t have to change for a long time, hopefully.
End of the road?
With these additions, main feature set of lazydraft is completed. There are still improvements I want to make though. Backlog is always full.
Changing the config to TOML or PKL (Currently not supported) might be a nice improvement for the future. If it was a big tool, I’d have to worry about migration but formats are pretty similar.
I might also add different types of writings here to my website in the future. Right now besides my blogposts there are also series (Transmission and this). To move them to Obsidian, I also need to implement the same folder config for them as well. This is not very optimal so changing the config to a list of folders might be on the horizon, depending on how many series I want to write :)