New Shortcuts

Again, because I got tired of typing it, there's a new shortcut for creating Amazon links to books music etc., and another one for Ishbadiddle Subjects.

<amazon>1931498717:Don't Think of an Elephant</amazon> will now code to Don't Think of an Elephant. The first part should be the ISBN (or the ASIN, the 10-character ID assigned to every item in Amazon), then a colon, then the title. Don't forget the end tag!

Similarly, <subject>Lists</subject> will automagically become Lists , which links to the index of posts on "Lists".

Finally, I fixed the problem where long URLs left in the comment box would go "out of bounds." They now break at 30 characters.

Boring "here's how it's done" stuff below the fold.

The Subject tag is a simple search-and-replace using MTMacro. MTMacroContent calls up what's between the tages, so that gets invoked three times:

<MTMacroDefine name="subject" ctag="subject"><a href="http://www.triptronix.net/mt/mt-search.cgi?IncludeBlogs=1&SearchField=keywords&Template=subject&CaseSearch=1&ResultDisplay=Ascending&search=<MTMacroContent>" title="Index of posts relating to <MTMacroContent>"><MTMacroContent></a>
</MTMacroDefine>

The Amazon one was a bit trickier, since there are two data chunks (the ISBN and the title) inside the same tag. I started by trying to nest three macros, but that didn't work, so I built a Regex for it:

<MTAddRegex name="amazon">s|<amazon>(\w{10}):(.*)</amazon>|<a href="http://www.amazon.com/exec/obidos/ASIN/$1/ref=nosim/ishbadiddle-20">$2</a>|gi</MTAddRegex>

Basically this looks for the amazon tag, then a 10-character string (which becomes $1), then a colon, then whatever's left ($2). In 2007, ISBN will upgrade to 13 characters, but I think I can wait until then to change the code.

<MTAddRegex name="breakurl">s|(\S{30})(\S{5,})|$1 $2|g</MTAddRegex>

This looks for a string that's at least 35 characters, and breaks it into a 30-character string, a space, and then whatever's left. A really long URL (over 60) will still go out of bounds, but hey, nobody's perfect.


M E-L posted this on November 17, 2004
It is filed under Site News

It is also indexed with the following tags: Movable Type |

Comments
Post a comment









Remember personal info?




Enter the following security code to prove that you are human:





Note: HTML is allowed in your comment. Please be patient as posting can take up to a minute depending on traffic. If you're planning on spamming, don't bother; URLs in comments will not be indexed by any search engine.


















Ishbadiddle buttonTriptronix buttonMovable Type buttonMT Plugins buttonCreative Commons buttonCSS Tableless buttonEdit Pad buttonMax Design buttonLogin buttonEmail button

1m blogsageless buttonNYC Blogger buttonGeoURL buttonBlogdex buttonBlogShares buttonBlogstreet buttonEatonweb buttonTechnorati button

DonorsChoose buttonFlying Spaghetti MonsterGet Firefox!Stand up for your rightsWin With Blingo!

Ishbadiddle Full Posts Feed ButtonIshbadiddle Posts Excerpts Feed ButtonBloglines subscribe buttonIshbadiddle LiveJournal Feed Button