I didn't know about https://gohugo.io/templates/data-templates/ Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
		
			
				
	
	
		
			12 lines
		
	
	
		
			470 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			12 lines
		
	
	
		
			470 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
{{ $scratch := .scratch }}
 | 
						|
{{ $scratch.Set "bestLength" -1 }}
 | 
						|
{{ $scratch.Set "bestUrl" (printf "%s/code/%s" .siteSourceUrl .path) }}
 | 
						|
{{ $filePath := .path }}
 | 
						|
{{ range $path, $url := .submoduleLinks }}
 | 
						|
{{ $bestLength := $scratch.Get "bestLength" }}
 | 
						|
{{ if and (le $bestLength (len $path)) (hasPrefix $filePath $path) }}
 | 
						|
{{ $scratch.Set "bestLength" (len $path) }}
 | 
						|
{{ $scratch.Set "bestUrl" (printf "%s%s" $url (strings.TrimPrefix $path $filePath)) }}
 | 
						|
{{ end }}
 | 
						|
{{ end }}
 |