Module:Citation/CS1/Identifiers: Difference between revisions
asin() calls isbn() so asin() must follow isbn();
m>Trappist the monk (synch from sandbox;) |
m>Trappist the monk (asin() calls isbn() so asin() must follow isbn();) |
||
Line 246: | Line 246: | ||
return text .. class; | return text .. class; | ||
end | end | ||
Line 489: | Line 450: | ||
return is_valid_isxn_13 (isbn_str), 'checksum'; | return is_valid_isxn_13 (isbn_str), 'checksum'; | ||
end | end | ||
end | |||
--[[--------------------------< A M A Z O N >------------------------------------------------------------------ | |||
Formats a link to Amazon. Do simple error checking: asin must be mix of 10 numeric or uppercase alpha | |||
characters. If a mix, first character must be uppercase alpha; if all numeric, asins must be 10-digit | |||
isbn. If 10-digit isbn, add a maintenance category so a bot or awb script can replace |asin= with |isbn=. | |||
Error message if not 10 characters, if not isbn10, if mixed and first character is a digit. | |||
This function is positioned here because it calls isbn() | |||
]] | |||
local function asin(id, domain) | |||
local err_cat = "" | |||
if not id:match("^[%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u]$") then | |||
err_cat = ' ' .. set_error ('bad_asin'); -- asin is not a mix of 10 uppercase alpha and numeric characters | |||
else | |||
if id:match("^%d%d%d%d%d%d%d%d%d[%dX]$") then -- if 10-digit numeric (or 9 digits with terminal X) | |||
if isbn( id ) then -- see if asin value is isbn10 | |||
add_maint_cat ('ASIN'); | |||
elseif not is_set (err_cat) then | |||
err_cat = ' ' .. set_error ('bad_asin'); -- asin is not isbn10 | |||
end | |||
elseif not id:match("^%u[%d%u]+$") then | |||
err_cat = ' ' .. set_error ('bad_asin'); -- asin doesn't begin with uppercase alpha | |||
end | |||
end | |||
if not is_set(domain) then | |||
domain = "com"; | |||
elseif in_array (domain, {'jp', 'uk'}) then -- Japan, United Kingdom | |||
domain = "co." .. domain; | |||
elseif in_array (domain, {'au', 'br', 'mx'}) then -- Australia, Brazil, Mexico | |||
domain = "com." .. domain; | |||
end | |||
local handler = cfg.id_handlers['ASIN']; | |||
return external_link_id({link=handler.link, | |||
label=handler.label, prefix=handler.prefix .. domain .. "/dp/", | |||
id=id, encode=handler.encode, separator = handler.separator}) .. err_cat; | |||
end | end | ||