The Code
This script uses a regular expression to match the special linking
format inside any post. If the pattern is found, it replaces
asin:ASIN with the
proper URL. Add the following code to a file
called asin
(no extension necessary).
# Blosxom Plugin: ASIN
# Author: Nelson Minar <nelson@monkey.org>
# Version: 20030301
# http://www.nelson.monkey.org/~nelson/weblog/
# License: Public Domain
# ASIN is a Blosxom plugin that simplifies linking into Amazon's catalog.
# The link format is not a guaranteed standard, in particular the
# ref=nosim part. For the authority see
# https://associates.amazon.com/exec/panama/associates/resources/build-&return;
links/individual-item-link.html
# Installation:
# Modify the $associateID (or don't :-)
# Drop asin into your plugins directory
package asin;
$associateID = 'insert associate ID';
sub start {
1;
}
sub rewriteASIN {
my ($url) = @_;
$url =~ s%"asin:(.+)"%"\"http://www.amazon.com/exec/obidos/ASIN/&return;
$1/ref=nosim/$associateID\""%ies;
return $url;
}
# Modify the body of stories by rewriting asin: URIs to real URLs
sub story {
my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
# Rewrite any <a href="asin:..."> tag in the post body
$$body_ref =~ s/(<a\s[^>]*href="asin:[^>]+>)/rewriteASIN($1)/geis;
1;
}
1;