Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:CiteGithub: Difference between revisions

From starcup wiki
No edit summary
No edit summary
Line 15: Line 15:
local trimmedPath = StringEx.replace(argPath, "https://github.com/teamstarcup/starcup/blob/", "")
local trimmedPath = StringEx.replace(argPath, "https://github.com/teamstarcup/starcup/blob/", "")
local trimIndex = trimmedPath:find("/")
local filePath = trimmedPath:sub(trimmedPath:find("/"))
local filePath = trimmedPath:sub(trimmedPath:find("/"))
Line 20: Line 21:
local displayedFilePath = filePath:sub(1, filePath:find("#"))
local displayedFilePath = filePath:sub(1, filePath:find("#"))
return string.format("[%s]", displayedFilePath)
return string.format("[%s]", trimIndex)
end
end


return CiteGithub
return CiteGithub

Revision as of 07:19, 30 May 2025

Documentation for this module may be created at Module:CiteGithub/doc

local CiteGithub = {}
local StringEx = require("Module:StringExtension")

local FILE_PATH_PREFIX = "https://github.com/teamstarcup/starcup/blob/"

function CiteGithub.main(frame)
	local args = frame:getParent().args
	local argPath = args[1]
	
	if not StringEx.startswith(argPath, FILE_PATH_PREFIX) then
		error("Invalid argument: string must point to a file in the starcup" .. 
			" github repository")
		return
	end
	
	local trimmedPath = StringEx.replace(argPath, "https://github.com/teamstarcup/starcup/blob/", "")
	local trimIndex = trimmedPath:find("/")
	local filePath = trimmedPath:sub(trimmedPath:find("/"))
	
	-- trim off line number range
	local displayedFilePath = filePath:sub(1, filePath:find("#"))
	
	return string.format("[%s]", trimIndex)
end

return CiteGithub