My goal was simple but it eluded me for ten years.

I do a lot of linkblogging on mitchw.blog. I prefer to have links formatted like this:

How Many Steps Do You Really Need? That’s the Wrong Question. Walking is important, but challenging yourself to go faster and higher can improve your health even more. nytimes.com

It’s esthetically pleasing, and the reader can see which website they’re being directed to. It’s the way Dave Winer formats it on the links page of his Scripting News blog, which is where I got the idea. I like it.

However, formatting links that way is just fussy enough that it’s inconvenient, particularly when I’m reading and blogging from the iPad and iPhone. I looked for automated tools that would work with my existing blogging software to create those links. Currently, I’m blogging on Micro.blog; previously I used WordPress. But I couldn’t find anything that worked quite the way I wanted.

Then I thought: Why not let ChatGPT try? I’d heard ChatGPT made an excellent coding assistant. Why not see if ChatGPT could do the whole thing?

So I did. You can read a transcript of my conversation with ChatGPT here, complete with code snippets, or read on here and I’ll walk you through it.

Getting started

I started by asking ChatGPT4:

I’m looking for a tool that would automatically convert URLs for posting to the web, to strip off everything but the domain and then link to the URL from the domain. The output should be in Markdown format. For example:

https://www.nytimes.com/2024/03/08/world/middleeast/gaza-aid-by-sea.html would become nytimes.com

https://news.yahoo.com/trump-set-finalize-rnc-takeover-051211725.html would become news.yahoo.com

https://en.wikipedia.org/wiki/Yorgos_Lanthimos would become en.wikipedia.org

You can see an example of that style of linking on this page: http://scripting.com/?tab=links

ChatGPT replied with a Python script that would do the job. I would have to edit the script manually to change the URLs.

A good start, but not what I was looking for.

I thought about using Drafts, a utility for the Mac, iPad and iPhone designed to be the place “where text starts.” You type some text into Drafts and then send the text to email, messages, Slack, your task manager, WordPress, whatever. It’s extremely customizable; users can write automations, known as Actions, to manipulate text or send notes to other apps.

I told ChatGPT:

Write me a plugin for the Drafts app that does the same thing using a URL in a draft. Here is the Drafts app https://getdrafts.com

ChatGPT wrote a Drafts action, along with instructions how I could install it. I ran the plugin and got an error. So I sent the error message to ChatGPT, which explained the problem to me and rewrote the code.

And it worked. The whole process took just a few minutes.

But then I ran into a glitch. Here’s how I explained it to ChatGPT:

Please modify the JavaScript so that if the URL starts with www, the www is not included in the output. For example, if the input is this:

Immigrants are less likely to commit crimes than U.S.-born Americans https://www.kpbs.org/news/national/2024/03/08/immigrants-are-less-likely-to-commit-crimes-than-u-s-born-americans-studies-find

The output is currently this:

Immigrants are less likely to commit crimes than U.S.-born Americans www.kpbs.org

Instead, it should be this:

Immigrants are less likely to commit crimes than U.S.-born Americans kpbs.org

ChatGPT revised the code to check for the presence of www in the URL, and remove that string if present. I updated the Drafts Action yet again, and it worked.

How about link previews?

Next, I asked ChatGPT to write an action that would generate a link preview in a post, in the style of Facebook, Mastodon, Threads, etc. I got that idea from the recent kottke.org redesign.

ChatGPT told me it could do that partially, but couldn’t fetch the title of the web page automatically because Drafts can’t access the Internet.

I replied:

You are incorrect. Drafts can extract the title. See this action for example code. directory.getdrafts.com/a/13y You’ll want to use open graph to get the information for the preview. Try again please.

ChatGPT corrected itself and generated an action for me. I got error messages and passed them on to ChatGPT, which corrected the action. We went back and forth until we generated an action that worked successfully. However, the output was ugly and I lost interest. Maybe I’ll come back to it another day.

Back to plan A

I returned to the original problem and asked ChatGPT for a slight modification.

Me: Let’s go back to the “Convert URLs to markdown” Drafts action. Ready to do a little more work on that one?

ChatGPT: Of course! Let’s continue working on the “Convert URLs to Markdown” Drafts action. What adjustments or additions would you like to make?

Me: I’d like to modify that script so there are brackets surrounding the domain link, with the brackets inside the link.

I provided an example, which included an escape character, \, in front of the square brackets, because I thought that was necessary to render the text properly.

ChatGPT responded with the correct code—which did not include the escape character, because it’s unnecessary.

You can read my conversation with ChatGPT in its entirety here.

I’m pleased by this, and I have a couple of ideas for other Drafts actions ChatGPT can create for me to automate blog and social media formatting.