Module:Aircraft category categories
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
UsageUsage
This module is meant to be used in {{Aircraft category categories}}. This module generates parent categories for common aircraft-related Commons categories such as Category:Piper PA-28-180 Cherokee built in 1967 and Category:Cessna 172 by year of manufacture. Data used by this module can be found at Module:Aircraft category categories/parent category. This module may not generarte all categories applicable to the aircraft type, however, given how diverse each family of aircraft is named.
{{#invoke:Aircraft category categories|main|''category_page_name''}}
Code
-- meant to be used in categories like "Piper PA-28-180 Cherokee built in 1967" or "Cessna 172 by year of manufacture" to
-- automatically place them in the correct parent category.
local p = {}
local String = require("string")
local parentCategories = require("Module:Aircraft category categories/parent category")
p.main = function(frame)
local pageName = frame.args[1]
local currentCategory, i, parentCategory
local aircraftByCategory = ""
-- XX built in YYYY
i = String.find(pageName, "built in %d")
if i then
currentCategory = String.sub(pageName, 1, i-2)
parentCategory = parentCategories[currentCategory]
if String.sub(parentCategory, -9) == " aircraft" then
aircraftByCategory = "[[Category:Aircraft built in " .. String.sub(pageName, -4) .. " by designation]]"
end
return "[[Category: " .. currentCategory .. " by year of manufacture|" .. String.sub(pageName, -4) .."]][[Category: ".. parentCategory .. String.sub(pageName, i-1) .. "| " .. currentCategory .. "]]" .. aircraftByCategory
end
-- XX by year of manufacture
i = String.find(pageName, "by year of manufacture")
if i then
currentCategory = String.sub(pageName, 1, i-2)
parentCategory = parentCategories[currentCategory]
if String.sub(parentCategory, -9) == " aircraft" then
aircraftByCategory = "[[Category:Aircraft by year of manufacture by type]]"
end
return "[[Category: " .. currentCategory .. "| " .. currentCategory .."]][[Category: " .. parentCategory .. " by year of manufacture| year]]" .. aircraftByCategory
end
-- XX by registration
i = String.find(pageName, "by registration")
if i then
currentCategory = String.sub(pageName, 1, i-2)
parentCategory = parentCategories[currentCategory]
if String.sub(parentCategory, -9) == " aircraft" then
aircraftByCategory = "[[Category:Aircraft by registration by type]]"
end
return "[[Category: " .. currentCategory .. "| registration]][[Category: " .. parentCategory .. " by registration| " .. currentCategory .."]]" .. aircraftByCategory
end
end
return p