Module:EzTumblr: Difference between revisions
Jump to navigation
Jump to search
>Corveroth (Let's see if we can't make this easier) |
>RivalRowan (Updated vorthosjay Tumblr title. Moved tabakrules and multiverseinreview to a new section as they no longer exist but I'm not sure if they're used anywhere and deleting them would break the reference.) |
||
(15 intermediate revisions by 4 users not shown) | |||
Line 2: | Line 2: | ||
-- Editors: make sure to carefully copy syntax, including the comma at the end of any new entry | -- Editors: make sure to carefully copy syntax, including the comma at the end of any new entry | ||
Ez.tumblrs = { | |||
-- WotC staff | -- WotC staff | ||
[" | ["markrosewater"] = { author = "Mark Rosewater", title = "Blogatog" }, | ||
["dougbeyermtg"] = { author = "Doug Beyer", title = "A Voice for Vorthos" }, | ["dougbeyermtg"] = { author = "Doug Beyer", title = "A Voice for Vorthos" }, | ||
["wizardsmagic"] = { author = "Wizards of the Coast", title = "The Official Magic: The Gathering Tumblr" }, | |||
-- Other notable MtG tumblrs | |||
["vorthosjay"] = { author = "Jay Annelli", title = "Ask Jay" }, | |||
-- Former MtG tumblrs | |||
["tabakrules"] = { author = "Matt Tabak", title = "Snarkham Asylum" }, | ["tabakrules"] = { author = "Matt Tabak", title = "Snarkham Asylum" }, | ||
[" | ["multiverseinreview"] = { author = "Squirle", title = "Multiverse in Review" }, | ||
} | |||
local ERR_MALFORMED = "Malformed URL" | |||
local ERR_UNKNOWN = "Unknown tumblr (use [[Template:TumblrRef]] or add to [[Module:EzTumblr]]?)" | |||
local ERR_NOTITLE = "No title in template or URL (missing slug?)" | |||
} | function Ez.getSupportedBlogs() | ||
local sorted = {} | |||
local out = "" | |||
for url, data in pairs(Ez.tumblrs) do | |||
table.insert(sorted, url) | |||
end | |||
table.sort(sorted) | |||
for _, url in ipairs(sorted) do | |||
out = out .. string.format("* %s.tumblr.com\n", url) | |||
end | |||
return out | |||
end | |||
-- Match the bit between the double-slash and the first period in the given URL | -- Match the bit between the double-slash and the first period in the given URL | ||
function Ez.getAuthor(tumblrAddress | function Ez.getAuthor(frame) | ||
local tumblrAddress = frame.args[1] | |||
local subdomain = tumblrAddress:match("^%w+://([^%.]+)") | local subdomain = tumblrAddress:match("^%w+://([^%.]+)") | ||
return tumblrs[subdomain].author | |||
assert(subdomain, ERR_MALFORMED) | |||
assert(Ez.tumblrs[subdomain], ERR_UNKNOWN) | |||
return Ez.tumblrs[subdomain].author | |||
end | end | ||
function Ez.getTitle(tumblrAddress | function Ez.getTitle(frame) | ||
local tumblrAddress = frame.args[1] | |||
local subdomain = tumblrAddress:match("^%w+://([^%.]+)") | local subdomain = tumblrAddress:match("^%w+://([^%.]+)") | ||
return tumblrs[subdomain].title | |||
assert(subdomain, ERR_MALFORMED) | |||
assert(Ez.tumblrs[subdomain], ERR_UNKNOWN) | |||
return Ez.tumblrs[subdomain].title | |||
end | |||
-- Generates a title for the post if not provided and the editor left the human-readable slug on the URL | |||
function Ez.createPostTitle(frame) | |||
local tumblrAddress = frame.args[1] | |||
local slug = tumblrAddress:match("/([%w%-]+)$") | |||
assert(slug, ERR_NOTITLE) | |||
slug = slug:gsub("^%l", string.upper) | |||
slug = slug:gsub("%-", " ") .. "..." | |||
return slug | |||
end | end | ||
return Ez | return Ez |
Latest revision as of 07:05, 9 April 2024
This is a module documentation subpage for Module:EzTumblr.
It contains usage information, categories, interlanguage links and other content that is not part of the original module page.
It contains usage information, categories, interlanguage links and other content that is not part of the original module page.
This module stores information about commonly referenced Tumblr accounts, and retrieves that information when provided a URL from a known Tumblr account.
You should not need to use this module directly. {{EzTumblr}} uses this module to simplify {{TumblrRef}}.
If you find that you are often referencing a Tumblr not known by this module, feel free to edit the table at the top. Please be careful to match the syntax used.
local Ez = {} -- Editors: make sure to carefully copy syntax, including the comma at the end of any new entry Ez.tumblrs = { -- WotC staff ["markrosewater"] = { author = "Mark Rosewater", title = "Blogatog" }, ["dougbeyermtg"] = { author = "Doug Beyer", title = "A Voice for Vorthos" }, ["wizardsmagic"] = { author = "Wizards of the Coast", title = "The Official Magic: The Gathering Tumblr" }, -- Other notable MtG tumblrs ["vorthosjay"] = { author = "Jay Annelli", title = "Ask Jay" }, -- Former MtG tumblrs ["tabakrules"] = { author = "Matt Tabak", title = "Snarkham Asylum" }, ["multiverseinreview"] = { author = "Squirle", title = "Multiverse in Review" }, } local ERR_MALFORMED = "Malformed URL" local ERR_UNKNOWN = "Unknown tumblr (use [[Template:TumblrRef]] or add to [[Module:EzTumblr]]?)" local ERR_NOTITLE = "No title in template or URL (missing slug?)" function Ez.getSupportedBlogs() local sorted = {} local out = "" for url, data in pairs(Ez.tumblrs) do table.insert(sorted, url) end table.sort(sorted) for _, url in ipairs(sorted) do out = out .. string.format("* %s.tumblr.com\n", url) end return out end -- Match the bit between the double-slash and the first period in the given URL function Ez.getAuthor(frame) local tumblrAddress = frame.args[1] local subdomain = tumblrAddress:match("^%w+://([^%.]+)") assert(subdomain, ERR_MALFORMED) assert(Ez.tumblrs[subdomain], ERR_UNKNOWN) return Ez.tumblrs[subdomain].author end function Ez.getTitle(frame) local tumblrAddress = frame.args[1] local subdomain = tumblrAddress:match("^%w+://([^%.]+)") assert(subdomain, ERR_MALFORMED) assert(Ez.tumblrs[subdomain], ERR_UNKNOWN) return Ez.tumblrs[subdomain].title end -- Generates a title for the post if not provided and the editor left the human-readable slug on the URL function Ez.createPostTitle(frame) local tumblrAddress = frame.args[1] local slug = tumblrAddress:match("/([%w%-]+)$") assert(slug, ERR_NOTITLE) slug = slug:gsub("^%l", string.upper) slug = slug:gsub("%-", " ") .. "..." return slug end return Ez