From 5091695e75b2db30b8926d8aa17164c84031bc77 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Sat, 17 Dec 2022 21:33:04 +0530 Subject: templates: repo and log --- routes/routes.go | 35 ++++++++++++++++++++++-------- routes/template.go | 2 +- static/style.css | 60 +++++++++++++++++++++++++++++++++++++++++++++++----- templates/index.html | 2 +- templates/log.html | 18 ++++++++++------ templates/nav.html | 3 +-- templates/repo.html | 56 ++++++++++++++++++------------------------------ templates/tree.html | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 168 insertions(+), 61 deletions(-) create mode 100644 templates/tree.html diff --git a/routes/routes.go b/routes/routes.go index 5a8d686..f52e86a 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -45,13 +45,7 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) { return } - var desc string - db, err := os.ReadFile(filepath.Join(path, "description")) - if err == nil { - desc = string(db) - } else { - desc = "" - } + desc := getDescription(path) infos = append(infos, info{ Name: dir.Name(), @@ -83,7 +77,7 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) { return } - files, err := gr.FileTree("") + commits, err := gr.Commits() if err != nil { d.Write500(w) log.Println(err) @@ -109,12 +103,25 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) { return } + tpath := filepath.Join(d.c.Dirs.Templates, "*") + t := template.Must(template.ParseGlob(tpath)) + + if len(commits) >= 5 { + commits = commits[:5] + } + data := make(map[string]any) data["name"] = name data["ref"] = mainBranch data["readme"] = readmeContent + data["commits"] = commits + data["desc"] = getDescription(path) + + if err := t.ExecuteTemplate(w, "repo", data); err != nil { + log.Println(err) + return + } - d.listFiles(files, data, w) return } @@ -283,3 +290,13 @@ func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, f) } + +func getDescription(path string) (desc string) { + db, err := os.ReadFile(filepath.Join(path, "description")) + if err == nil { + desc = string(db) + } else { + desc = "" + } + return +} diff --git a/routes/template.go b/routes/template.go index dc1ec35..6af5cfe 100644 --- a/routes/template.go +++ b/routes/template.go @@ -37,7 +37,7 @@ func (d *deps) listFiles(files []git.NiceTree, data map[string]any, w http.Respo data["files"] = files data["meta"] = d.c.Meta - if err := t.ExecuteTemplate(w, "repo", data); err != nil { + if err := t.ExecuteTemplate(w, "tree", data); err != nil { log.Println(err) return } diff --git a/static/style.css b/static/style.css index 5581e3a..df2c81c 100644 --- a/static/style.css +++ b/static/style.css @@ -6,12 +6,16 @@ --gray: #6a6a6a; --dark: #444; --darker: #222; + + --sans-font: "InterVar", -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif; + --display-font: "InterDisplay", -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif; + --mono-font: monospace; } html { background: var(--light); -webkit-text-size-adjust: none; - font-family: "InterVar", -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif; + font-family: var(--sans-font); } ::selection { @@ -38,7 +42,7 @@ main, footer { } main h1, h2, h3, .small-heading { - font-family: "InterDisplay", -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif; + font-family: var(--display-font); font-weight: 500; } @@ -94,19 +98,65 @@ a:hover { .index { display: grid; - grid-template-columns: 6em 1fr 7em; + grid-template-columns: 6em 1fr minmax(0, 7em); grid-row-gap: 0.5em; + min-width: 0; } .index-headings { display: grid; - grid-template-columns: 6em 1fr 7em; + grid-template-columns: 6em 1fr minmax(0, 7em); padding-bottom: 1.2em; padding-top: 1.2em; + min-width: 0; +} + +.desc { + color: var(--gray); + font-style: italic; +} + +.tree { + display: grid; + grid-template-columns: 8em minmax(0, 1fr); + grid-row-gap: 0.5em; + grid-column-gap: 1em; + min-width: 0; +} + +.log { + display: grid; + grid-template-columns: 20rem minmax(0, 1fr); + grid-row-gap: 0.8em; + grid-column-gap: 8rem; + margin-bottom: 2em; + padding-bottom: 1em; + border-bottom: 1.5px solid var(--medium-gray); } -@media (max-width: 385px) { +.log pre { + white-space: pre-wrap; +} + +.mode { + font-family: var(--mono-font); +} + +.readme pre { + white-space: pre-wrap; +} + +@media (max-width: 600px) { .index { grid-row-gap: 0.8em; } + + .log { + grid-template-columns: 1fr; + grid-row-gap: 0em; + } + + .commit-info:not(:last-child) { + padding-bottom: 1.5rem; + } } diff --git a/templates/index.html b/templates/index.html index 02c62ef..25cedfb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -16,7 +16,7 @@
{{ range .info }}
{{ .Name }}
-
{{ .Desc }}
+
{{ .Desc }}
{{ .Idle }}
{{ end }}
diff --git a/templates/log.html b/templates/log.html index de7b200..c4ee9c3 100644 --- a/templates/log.html +++ b/templates/log.html @@ -9,13 +9,17 @@ {{ template "nav" . }}
- {{ $repo := .name }} - {{ range .commits }} -

{{ slice .Hash.String 0 8 }} - — {{ .Author.Name }} - {{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}

-

{{ .Message }}

- {{ end }} + {{ $repo := .repo }} +
+ {{ range .commits }} +
+
{{ slice .Hash.String 0 8 }}
+
{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}
+
{{ .Message }}
+
+
{{ .Author.Name }} {{ .Author.Email }}
+ {{ end }} +
diff --git a/templates/nav.html b/templates/nav.html index d0d384d..51c9a34 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -1,9 +1,8 @@ {{ define "nav" }}