all: go-import, clone url

This commit is contained in:
Anirudh Oppiliappan 2022-12-18 20:00:19 +05:30
parent 2e3c3103c4
commit d0d636aa89
No known key found for this signature in database
GPG key ID: 8A93F96F78C5D4C4
7 changed files with 54 additions and 9 deletions

View file

@ -14,6 +14,10 @@ dirs:
meta: meta:
title: git good title: git good
description: i think it's a skill issue description: i think it's a skill issue
misc:
goImport:
prettyURL: icyphox.sh
server: server:
fqdn: git.icyphox.sh
host: 127.0.0.1 host: 127.0.0.1
port: 5555 port: 5555

View file

@ -21,7 +21,13 @@ type Config struct {
Title string `yaml:"title"` Title string `yaml:"title"`
Description string `yaml:"description"` Description string `yaml:"description"`
} `yaml:"meta"` } `yaml:"meta"`
Misc struct {
GoImport struct {
PrettyURL string `yaml:"string"`
} `yaml:"goImport"`
} `yaml:"misc"`
Server struct { Server struct {
FQDN string `yaml:"fqdn,omitempty"`
Host string `yaml:"host"` Host string `yaml:"host"`
Port int `yaml:"port"` Port int `yaml:"port"`
} `yaml:"server"` } `yaml:"server"`

View file

@ -1,6 +1,7 @@
package routes package routes
import ( import (
"fmt"
"html/template" "html/template"
"log" "log"
"net/http" "net/http"
@ -112,6 +113,15 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
return return
} }
cloneURL := fmt.Sprintf("https://%s/%s", d.c.Server.FQDN, name)
if d.c.Misc.GoImport.PrettyURL == "" {
d.c.Misc.GoImport.PrettyURL = cloneURL
}
goImport := fmt.Sprintf(`<meta name="go-import" content="%s git %s">`,
d.c.Misc.GoImport.PrettyURL, cloneURL)
tpath := filepath.Join(d.c.Dirs.Templates, "*") tpath := filepath.Join(d.c.Dirs.Templates, "*")
t := template.Must(template.ParseGlob(tpath)) t := template.Must(template.ParseGlob(tpath))
@ -125,6 +135,8 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
data["readme"] = readmeContent data["readme"] = readmeContent
data["commits"] = commits data["commits"] = commits
data["desc"] = getDescription(path) data["desc"] = getDescription(path)
data["clone"] = cloneURL
data["goimport"] = template.HTML(goImport)
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

@ -111,6 +111,14 @@ a:hover {
min-width: 0; min-width: 0;
} }
.clone-url {
padding-top: 2rem;
}
.clone-url pre {
color: var(--dark);
}
.desc { .desc {
color: var(--gray); color: var(--gray);
font-style: italic; font-style: italic;
@ -146,6 +154,11 @@ a:hover {
white-space: pre-wrap; white-space: pre-wrap;
} }
.readme {
padding-bottom: 2rem;
border-bottom: 1.5px solid var(--medium-gray);
}
.diff { .diff {
margin: 1rem 0 1rem 0; margin: 1rem 0 1rem 0;
padding: 1rem 0 1rem 0; padding: 1rem 0 1rem 0;
@ -160,10 +173,6 @@ a:hover {
padding: 1rem 0 1rem 0; padding: 1rem 0 1rem 0;
} }
.commit-email {
color: var(--gray);
}
.commit-email:before { .commit-email:before {
content: '<'; content: '<';
} }
@ -230,7 +239,7 @@ a:hover {
.commit-info { .commit-info {
color: var(--gray); color: var(--gray);
font-size: 14px; padding-bottom: 1.5rem;
} }
@media (max-width: 600px) { @media (max-width: 600px) {

View file

@ -10,8 +10,11 @@
<pre> <pre>
{{- .commit.Message -}} {{- .commit.Message -}}
</pre> </pre>
<p>{{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</p> <div class="commit-info">
<p>{{ .commit.Author.Name }} <span class="commit-email">{{ .commit.Author.Email}}</span></p> {{ .commit.Author.Name }} <span class="commit-email">{{ .commit.Author.Email}}</span>
<div>{{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div>
</div>
<p>commit: <a href="/{{ .name }}/commit/{{ .commit.This }}"> <p>commit: <a href="/{{ .name }}/commit/{{ .commit.This }}">
{{ .commit.This }} {{ .commit.This }}
</a> </a>

View file

@ -4,6 +4,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<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">
{{ if .goimport }}
{{ .goimport }}
{{ end }}
<!-- other meta tags here --> <!-- other meta tags here -->
</head> </head>
{{ end }} {{ end }}

View file

@ -25,12 +25,20 @@
</div> </div>
{{ end }} {{ end }}
</div> </div>
{{- if .readme }}
<article class="readme"> <article class="readme">
<pre> <pre>
{{- if .readme }}{{ .readme }}{{- end -}} {{- .readme -}}
</pre> </pre>
</article> </article>
{{- end -}}
<div class="clone-url">
<strong>clone</strong>
<pre>
git clone {{ .clone -}}
</pre>
</div>
</main> </main>
</body> </body>
</html> </html>