Crosslinking blog posts
Linking out to other sites from my blog posts is not a problem, but I’ve been pondering how I link to blog posts I’ve written previously without being wedded to one particular structure or platform.
The problem
As outlined in a previous post on using Git to aid in my writing process, while I’m writing my posts I save each one in its own folder in a larger drafts folder. Even when I’ve published them to my blog, I have an archives
folder which retains each post in its own folder, because I use Git to version the content and keep track of my writing and moving it out of these folders would mean losing that history (or doing some complicated merging of repositories).
On Scriptogram, however, all the posts/files are in one folder together. The same is true of my posted
folder. Linking directly to other posts is pointless, since in my own folders each post is in a sub-folder whereas online and in posted
they are at the same level. Besides, which one would I link to?
For example, I could hard-code a link to archives/2014-11-02T20-09_mustache-vs-handlebars-scoping/2014-11-02T20-09_mustache-vs-handlebars-scoping
from my draft post. But when I publish it to, for example, Scriptogram the link would need to be /guypursey/post/mustache-vs.-handlebars-scoping
to reflect the way Scriptogram is structured and the actual title of the post.
The solution (for now)
I know that when I’m writing a draft I’m likely to be linking back to a previous post rather than forward to another draft. Even if I were to link to something not yet published, it would need to be corrected to something that was published before I went live with it.
Now that the renaming of files as I move them is automatic as outlined in my last post, there is a rigid convention that can be followed for linking to posts. I know that the filename should always be the same as the folder name unless it’s been manually changed because there is a script that makes it that way.
As a result, I can use a standard form of link that can then be translated into a specific link based on which platform I’m posting too. For now, I’ve decided that any links beginning with /$/
indicate that the link is to another post. For example …
/$/2014-11-02T20-09_mustache-vs-handlebars-scoping
… will link to my blog post comparing Mustache and Handlebars a couple of weeks ago.
If I let a renderer handle what to do with the \$\
part of within my structure, it doesn’t matter if my post is in /archives/2014-11-02T20-09_mustache-vs-handlebars-scoping
or just /posted
.
I can also accommodate Scriptogram because it allows for a metadata field I have not used up until now: Slug
. Using this I can tell Scriptogram what the link for a post should be so that they all have the same reference.
I’ve built this into autoscrp.sh
now:
metadata=$(echo -e "Title: $bareheader Date: $datetime Tags: $tags Slug: $1 ")
I’ve also added some code that parses the content for any $
-prefixed links that ought to be converted into the relevant Scriptogram details:
username=$(<"$DIR"/scrpname.txt)
fileparsed="${contents//\(\/\$\//\(\/$username\/post\/}"
These details rely in part on another outside file – scrpname.txt
from which I pull the pathname for the blog to build the link.
What next?
I need to republish all my blog posts to make sure the slugs are up to date! But to do that I need to ensure I have a robust republish method that isn’t going to rewrite all the dates.