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

Module:SourceLink: Difference between revisions

From starcup wiki
Created page with "local SourceLink = {} function SourceLink.main(frame) local args = frame.args return string.format( "[https://github.com/teamstarcup/starcup/blob/master/%s]", args[1] ) end return SourceLink"
 
stargazer: a66e644b10
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:


function SourceLink.main(frame)
function SourceLink.main(frame)
local args = frame.args
local args = frame:getParent().args
return string.format( "[https://github.com/teamstarcup/starcup/blob/master/%s]", args[1] )
local argPath = args[1]
local lastSlashIndex = argPath:reverse():find("/")
local displayText = argPath:sub(#argPath - lastSlashIndex + 2)
local fragmentIndex = displayText:find("#")
if fragmentIndex then
fragmentIndex = fragmentIndex - 1
end
displayText = displayText:sub(1, fragmentIndex)
return string.format( "[https://github.com/teamstarcup/starcup/blob/a66e644b10ba9e610cd92c1e8a86a76a1299a526/%s %s]", argPath, displayText )
end
end


return SourceLink
return SourceLink

Latest revision as of 14:43, 27 May 2025

Documentation

This module generates an external link to the GitHub repository at the (hopefully) current commit hash of the main branch. It is used for pointing somewhere specific in the codebase.

Usage

{{SourceLink|Resources/Prototypes/Entities/Objects/Tools/lantern.yml#L1}}

... which generates the following link: lantern.yml


local SourceLink = {}

function SourceLink.main(frame)
	local args = frame:getParent().args
	local argPath = args[1]
	local lastSlashIndex = argPath:reverse():find("/")
	local displayText = argPath:sub(#argPath - lastSlashIndex + 2)
	local fragmentIndex = displayText:find("#")
	if fragmentIndex then
		fragmentIndex = fragmentIndex - 1
	end
	displayText = displayText:sub(1, fragmentIndex)
	return string.format( "[https://github.com/teamstarcup/starcup/blob/a66e644b10ba9e610cd92c1e8a86a76a1299a526/%s %s]", argPath, displayText )
end

return SourceLink