Jump to content

Module:R:Autenrieth

From Wiktionary, the free dictionary

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local collisions = require("Module:R:Perseus/collision-data")

function is_collision(x)
  return collisions[mw.ustring.lower(x)] ~= nil
end

function format_perseus_url(title, beta, redirect)
	local url_redirect_lhs = 'http://www.perseus.tufts.edu/hopper/resolveform?type=exact&lookup='
	local url_entry_lhs = 'http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:1999.04.0073:entry='
	local url_rhs = redirect and '&lang=greek' or ''
	return (redirect and url_redirect_lhs or url_entry_lhs)..beta..url_rhs
end

function format_perseus_wikilink(title, beta, redirect)
	local url = format_perseus_url(title, beta, redirect)
	local w_link = '«['..url..' '..title..']» in '
	return (beta == '' and '' or w_link)
end

function export.create(frame)
	local args = frame:getParent().args
	local title = args['w'] or mw.title.getCurrentTitle().text
	local beta = args[1] or require("Module:grc-polytonic-to-perseus-betacode").polytonic_to_perseus_betacode(title) --polytonic_to_perseus_beta(title)
	local redirect = is_collision(title) and not args[1] and not args['w']
	return format_perseus_wikilink(title, beta, redirect)
end

return export