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 1: Line 1:
local CiteGithub = {}
local CiteGithub = {}
require("Module:StringExtension")
local FILE_PATH_PREFIX = "https://github.com/teamstarcup/starcup/blob/"


function CiteGithub.main(frame)
function CiteGithub.main(frame)
Line 5: Line 8:
local argPath = args[1]
local argPath = args[1]
-- trim off beginning of link
if not argPath:startswith(FILE_PATH_PREFIX) then
local hashStartIndex = argPath:find("https://github.com/teamstarcup/starcup/blob/")
error("Invalid argument: string must point to a file in the starcup" ..
local trimmedPath = argPath:sub(hashStartIndex)
" github repository")
return
end
-- trim off commit hash
local trimmedPath = argPath:replace("https://github.com/teamstarcup/starcup/blob/")
local filePath = trimmedPath:sub(trimmedPath:find("/"))
local filePath = trimmedPath:sub(trimmedPath:find("/"))

Revision as of 07:14, 30 May 2025

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

local CiteGithub = {}
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 argPath:startswith(FILE_PATH_PREFIX) then
		error("Invalid argument: string must point to a file in the starcup" .. 
			" github repository")
		return
	end
	
	local trimmedPath = argPath:replace("https://github.com/teamstarcup/starcup/blob/")
	local filePath = trimmedPath:sub(trimmedPath:find("/"))
	
	-- trim off line number range
	local displayedFilePath = trimmedPath:sub(1, trimmedPath:find("#"))
	
	return string.format("[%s]", trimmedPath)
end

return CiteGithub