From dfd2bbc52f8ee4437ad07e6cf5b6bf0cf755b3bb Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Thu, 17 Oct 2019 11:20:02 -0400 Subject: internal/frontend: translate relative non-image links in readmes If a Readme has a relative link that is not an image, convert it to an absolute link to the file using source info. Fixes b/140250096. Change-Id: I9ca629963ca87d7605c0217e49671b33c7dd0f86 Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/576296 CI-Result: Cloud Build Reviewed-by: Robert Findley Reviewed-by: Julie Qiu --- internal/source/source.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'internal/source/source.go') diff --git a/internal/source/source.go b/internal/source/source.go index fa4dc551..289ffb6d 100644 --- a/internal/source/source.go +++ b/internal/source/source.go @@ -63,6 +63,9 @@ func (i *Info) ModuleURL() string { // DirectoryURL returns a URL for a directory relative to the module's home directory. func (i *Info) DirectoryURL(dir string) string { + if i == nil { + return "" + } return strings.TrimSuffix(expand(i.templates.Directory, map[string]string{ "repo": i.repoURL, "commit": i.commit, @@ -72,6 +75,9 @@ func (i *Info) DirectoryURL(dir string) string { // FileURL returns a URL for a file whose pathname is relative to the module's home directory. func (i *Info) FileURL(pathname string) string { + if i == nil { + return "" + } return expand(i.templates.File, map[string]string{ "repo": i.repoURL, "commit": i.commit, @@ -81,6 +87,9 @@ func (i *Info) FileURL(pathname string) string { // LineURL returns a URL referring to a line in a file relative to the module's home directory. func (i *Info) LineURL(pathname string, line int) string { + if i == nil { + return "" + } return expand(i.templates.Line, map[string]string{ "repo": i.repoURL, "commit": i.commit, -- cgit v1.3