only add go meta import tag if go.mod exists in repo root

This is a multipart message in MIME format.

Pretty self-explanitory :3

Signed-off-by: Derek Stevens <nilix@nilfm.cc>
This commit is contained in:
Derek Stevens 2023-01-31 21:30:40 -07:00 committed by Anirudh Oppiliappan
parent 3060c752f8
commit de046690c0
No known key found for this signature in database
GPG Key ID: 8A93F96F78C5D4C4
3 changed files with 9 additions and 1 deletions

View File

@ -151,6 +151,7 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
data["commits"] = commits data["commits"] = commits
data["desc"] = getDescription(path) data["desc"] = getDescription(path)
data["servername"] = d.c.Server.Name data["servername"] = d.c.Server.Name
data["gomod"] = isGoModule(gr)
if err := t.ExecuteTemplate(w, "repo", data); err != nil { if err := t.ExecuteTemplate(w, "repo", data); err != nil {
log.Println(err) log.Println(err)

View File

@ -3,8 +3,15 @@ package routes
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"git.icyphox.sh/legit/git"
) )
func isGoModule(gr *git.GitRepo) bool {
_, err := gr.FileContent("go.mod")
return err == nil
}
func getDescription(path string) (desc string) { func getDescription(path string) (desc string) {
db, err := os.ReadFile(filepath.Join(path, "description")) db, err := os.ReadFile(filepath.Join(path, "description"))
if err == nil { if err == nil {

View File

@ -5,7 +5,7 @@
<link rel="stylesheet" href="/static/style.css" type="text/css"> <link rel="stylesheet" href="/static/style.css" type="text/css">
<link rel="stylesheet" href="https://cdn.icyphox.sh/fonts/inter.css" type="text/css"> <link rel="stylesheet" href="https://cdn.icyphox.sh/fonts/inter.css" type="text/css">
<link rel="icon" type="image/png" size="32x32" href="/static/legit.png"> <link rel="icon" type="image/png" size="32x32" href="/static/legit.png">
{{ if .servername }} {{ if and .servername .gomod }}
<meta name="go-import" content="{{ .servername}}/{{ .name }} git https://{{ .servername }}/{{ .name }}"> <meta name="go-import" content="{{ .servername}}/{{ .name }} git https://{{ .servername }}/{{ .name }}">
{{ end }} {{ end }}
<!-- other meta tags here --> <!-- other meta tags here -->