Over the past few days I’ve been playing with ChatGPT, getting it to help me tinker with PHP to interact with the Weblog.LOL API. Not so much, necessarily, because I was going to create something in PHP to manage things locally (although I thought about it) but more because I just wanted to see if I could understand how things worked.
While I have, in fact, mostly began to grasp how things work, and I do now have a PHP script that backs up my blog files to my VPS overnight, what I really started to think about was whether or not I could post directly from my editor-of-choice: Bear’s stand-alone Markdown editor, Panda.
Before the diversion into PHP and ChatGPT, I briefly did play around with Shortcuts, and did manage to post a test blog post elsewhere, but through a pop-up text modal, not directly from Panda. I couldn’t quite get my head into the right place to sit down and figure it out.
Technically, I haven’t quite exactly figured it out even now, as what I’ve cobbled together actually depends upon copying my Panda text to the clipboard and then firing off a Shortcut, but it does work. Maybe, if Bear follows through on potential plans to keep Panda as its own, separate product, that might bring more direct interplay with Shortcuts, too.
I won’t be using this workflow in production until we can post to the API without specifying a unique ID every time, something this workflow doesn’t allow me to incorporate. This is on the to-do list, so I have some meantime to see if there otherwise are any wrinkles to smooth out.
My ultimate goal here is to be able to write all my posts in Panda, publish them through the API via Shortcuts, and then somehow automate a fairly regular backing up directly to an iCloud folder through scripts run on my laptop.
What really would be nice is if I could figure out a way to publish a post this way and then immediately use the API to retrieve my latest post, for which there is an endpoint, so it’s safely stowed in the backup folder right away. I’ll spend some time this weekend or next week seeing if I can suss that one out.
If you’re interested, the Shortcuts recipe consists of just three elements, but as I said: you have to hardcode a unique ID into it right now, so it’s really only valuable for testing.
- Get clipboard
- Get contents of
- Method: POST
- Key: Authorization
- Value: Your API Key
- Request Body: File
This last will create another pane up top with its own settings, which should be configured as follows.
- If there’s no input:
I’ve now got my Panda folder in iCloud set up with a
draftsfolder, and a
postsfolder. On my laptop, I’ve a PHP script which uses the API to get my latest entry and save it into that
postsfolder, keeping it in sync with what exists on the Weblog.LOL server.
Basically, I’ll manually run that script at some point after publishing a new post. I’ve also three other PHP scripts, in case I need to save updated copies of my configuration file, my main template, or make a fresh archive of all of my entries, which will be needed as I’m filling in old posts during the restoration.
I’ve now also got two new Shortcuts: one for updating my configuration file, and one for updating my main template, each modeled after the Shortcut to post a new entry. To all three I’ve added an alert dialogue warning me of what I’m about to do, to help prevent, say, me overwriting my configuration file with a blog post.
Out of nowhere the next day I suddenly solved the Shortcuts problem that was preventing me from using Shortcuts instead of PHP to retrieve the latest blog post. So, now the only thing I’d still be using PHP for is to grab the full backup of all posts. I think there’s a way to do that in Shortcuts, too, but I’m going to hold off because I’m sure it requires some looping.
On something of a tear, now I also do have a Shortcut for retrieving all weblog entries, obviating the need for any of the original PHP scripts. The only API call for which I didn’t make a Shortcut was the one to delete a weblog entry.