2022-07-11 21:47:22 +01:00
|
|
|
package outputMeta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PackageMetaTagOutputter struct {
|
|
|
|
BasePath string
|
|
|
|
Username string //If set, the outputter will do /{repo}/ for repos rather than /{user}/{repo}/
|
|
|
|
BasePrefixURL string
|
|
|
|
SuffixDirectoryURL string
|
|
|
|
SuffixFileURL string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) GetMetaTags(pathIn string) string {
|
2022-07-12 11:04:25 +01:00
|
|
|
return "<meta name=\"go-import\" content=\"" + pkgMTO.GetMetaContentForGoImport(pathIn) + "\">\r\n" +
|
|
|
|
"<meta name=\"go-source\" content=\"" + pkgMTO.GetMetaContentForGoSource(pathIn) + "\">"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoImport(pathIn string) string {
|
|
|
|
return pkgMTO.getPrefix(pathIn) + " git " + pkgMTO.getHomeURL(pathIn)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoSource(pathIn string) string {
|
|
|
|
return pkgMTO.getPrefix(pathIn) + " " + pkgMTO.getHomeURL(pathIn) + " " +
|
|
|
|
pkgMTO.getDirectoryURL(pathIn) + " " + pkgMTO.getFileURL(pathIn)
|
2022-07-11 21:47:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) assureBasePrefixURL() (failed bool) {
|
|
|
|
if pkgMTO.BasePrefixURL == "" {
|
|
|
|
if pkgMTO.BasePath == "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
pkgMTO.BasePrefixURL = "http://" + pkgMTO.BasePath
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) getPrefix(pathIn string) string {
|
|
|
|
if pkgMTO.BasePath == "" {
|
|
|
|
return "_"
|
|
|
|
}
|
2022-07-12 12:01:53 +01:00
|
|
|
return path.Join(pkgMTO.BasePath, pathIn)
|
2022-07-11 21:47:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) getHomeURL(pathIn string) string {
|
|
|
|
if pkgMTO.assureBasePrefixURL() {
|
|
|
|
return "_"
|
|
|
|
}
|
|
|
|
|
|
|
|
if pkgMTO.Username == "" {
|
|
|
|
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Clean(pathIn), "/")
|
|
|
|
} else {
|
|
|
|
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn), "/")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) getDirectoryURL(pathIn string) string {
|
|
|
|
if pkgMTO.assureBasePrefixURL() || pkgMTO.SuffixDirectoryURL == "" {
|
|
|
|
return "_"
|
|
|
|
}
|
|
|
|
|
|
|
|
if pkgMTO.Username == "" {
|
|
|
|
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pathIn, pkgMTO.SuffixDirectoryURL), "/")
|
|
|
|
} else {
|
|
|
|
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn, pkgMTO.SuffixDirectoryURL), "/")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkgMTO *PackageMetaTagOutputter) getFileURL(pathIn string) string {
|
|
|
|
if pkgMTO.assureBasePrefixURL() || pkgMTO.SuffixFileURL == "" {
|
|
|
|
return "_"
|
|
|
|
}
|
|
|
|
|
|
|
|
if pkgMTO.Username == "" {
|
|
|
|
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pathIn, pkgMTO.SuffixFileURL), "/")
|
|
|
|
} else {
|
|
|
|
return pkgMTO.BasePrefixURL + "/" + strings.TrimLeft(path.Join(pkgMTO.Username, pathIn, pkgMTO.SuffixFileURL), "/")
|
|
|
|
}
|
|
|
|
}
|