Changes
12 changed files (+104/-47)
-
-
@@ -0,0 +1,16 @@/* Copyright 2026 Shota FUJI <pockawoooh@gmail.com> * SPDX-License-Identifier: MIT */ .diagnosis { font-family: var(--font-mono); font-size: var(--font-sm); border: 1px solid var(--color-border-strong); display: block; width: 100%; padding: var(--space-md) 1em; field-sizing: content; border-radius: var(--radii-sm); resize: none; }
-
-
-
@@ -11,18 +11,34 @@ SPDX-License-Identifier: MIT{{- if .Config.Meta.Description }} <meta name="description" content="{{ .Config.Meta.Description }}" /> {{- end }} <link rel="stylesheet" href="/static/errorpage.css" /> </head> <body> <header> <ol> <li> <a href="/">Top</a> </li> </ol> <header class="header"> <div class="header-title"> <h1 class="header-title--name">{{ .Config.Meta.Title }}</h1> <p class="header-title--description">{{ .Config.Meta.Description }}</p> </div> </header> <main> <main class="main"> <h1>Page not found</h1> <p> URL is incorrect or this page has been deleted. Browse from <a href="/">top page</a> to find the page you're looking for. </p> <details> <summary>If you are sure this is a correct URL</summary> <p> If you belive this website is misbehaving, contact the website owner with this text: </p> <textarea class="diagnosis" readonly>{{ .Diagnosis }}</textarea> <p> If you're the website owner and think this is a legit's bug, please submit a bug report at <a href="https://tangled.org/pocka.jp/legit/issues">here</a>. </p> </details> </main> {{ template "site-footer" . }} </body> </html> {{- end }}
-
-
-
@@ -11,19 +11,30 @@ SPDX-License-Identifier: MIT{{- if .Config.Meta.Description }} <meta name="description" content="{{ .Config.Meta.Description }}" /> {{- end }} <link rel="stylesheet" href="/static/errorpage.css" /> </head> <body> <header> <ol> <li> <a href="/">Top</a> </li> </ol> <header class="header"> <div class="header-title"> <h1 class="header-title--name">{{ .Config.Meta.Title }}</h1> <p class="header-title--description">{{ .Config.Meta.Description }}</p> </div> </header> <main> <h1>Internal error</h1> <p>Sorry, we can't serve this page due to our application error.</p> <main class="main"> <h1>Internal server error</h1> <p> Sorry, we can't serve this page due to our application error. Reload this page or browse from <a href="/">top page</a>. </p> <p> Please contact the website owner with this text: </p> <textarea class="diagnosis" readonly>{{ .Diagnosis }}</textarea> <p> If you're the website owner, please submit a bug report at <a href="https://tangled.org/pocka.jp/legit/issues">here</a>. </p> </main> {{ template "site-footer" . }} </body> </html> {{- end }}
-
-
-
@@ -245,10 +245,16 @@ type repoCommitData struct {type error404Data struct { // Config represents a resolved config based on "config.yaml". Config *config.Config // Diagnosis is debug text supposed to attach to a bug report for website owner. Diagnosis string } // error500Data is a data object passed to "500" template. type error500Data struct { // Config represents a resolved config based on "config.yaml". Config *config.Config // Diagnosis is debug text supposed to attach to a bug report for website owner. Diagnosis string }
-
-
-
@@ -5,12 +5,14 @@ package routesimport ( "errors" "fmt" "html/template" "io/fs" "log" "net/http" "os" "path/filepath" "time" "github.com/pocka/legit/config" "github.com/pocka/legit/git"
-
@@ -78,9 +80,12 @@ func (d *deps) template() *template.Template {return t } func (d *deps) write404(w http.ResponseWriter) { func (d *deps) write404(w http.ResponseWriter, r *http.Request) { timestamp := time.Now().Format(time.RFC3339) data := error404Data{ Config: d.c, Config: d.c, Diagnosis: fmt.Sprintf("Status: 404\nTimestamp: %s\nURL: %s\nUA: %s", timestamp, r.URL, r.UserAgent()), } w.WriteHeader(404)
-
@@ -89,9 +94,12 @@ func (d *deps) write404(w http.ResponseWriter) {} } func (d *deps) write500(w http.ResponseWriter) { func (d *deps) write500(w http.ResponseWriter, r *http.Request) { timestamp := time.Now().Format(time.RFC3339) data := error500Data{ Config: d.c, Config: d.c, Diagnosis: fmt.Sprintf("Status: 500\nTimestamp: %s\nURL: %s\nUA: %s", timestamp, r.URL, r.UserAgent()), } w.WriteHeader(500)
-
-
-
@@ -12,7 +12,7 @@ import (func (d *deps) serveInfoRefs(w http.ResponseWriter, r *http.Request) { repo, err := d.resolveRepository(r.PathValue("name")) if err != nil { d.write404(w) d.write404(w, r) return }
-
@@ -34,7 +34,7 @@ func (d *deps) serveInfoRefs(w http.ResponseWriter, r *http.Request) {func (d *deps) serveUploadPack(w http.ResponseWriter, r *http.Request) { repo, err := d.resolveRepository(r.PathValue("name")) if err != nil { d.write404(w) d.write404(w, r) return }
-
-
-
@@ -17,7 +17,7 @@ import (func (d *deps) multiplex(w http.ResponseWriter, r *http.Request) { name := r.PathValue("name") if d.isIgnored(name) { d.write404(w) d.write404(w, r) return }
-
-
-
@@ -13,14 +13,14 @@ func (d *deps) serveRepoTree(w http.ResponseWriter, r *http.Request) {ref := r.PathValue("ref") gr, name, err := d.openRepository(r.PathValue("name"), ref) if err != nil { d.write404(w) d.write404(w, r) return } treePath := r.PathValue("rest") files, err := gr.FileTree(treePath) if err != nil { d.write500(w) d.write500(w, r) log.Println(err) return }
-
@@ -54,7 +54,7 @@ func (d *deps) serveArchive(w http.ResponseWriter, r *http.Request) {// TODO: extend this to add more files compression (e.g.: xz) if !strings.HasSuffix(file, ".tar.gz") { d.write404(w) d.write404(w, r) return }
-
@@ -68,7 +68,7 @@ func (d *deps) serveArchive(w http.ResponseWriter, r *http.Request) {gr, name, err := d.openRepository(name, ref) if err != nil { d.write404(w) d.write404(w, r) return }
-
@@ -97,13 +97,13 @@ func (d *deps) serveDiff(w http.ResponseWriter, r *http.Request) {ref := r.PathValue("ref") gr, name, err := d.openRepository(r.PathValue("name"), ref) if err != nil { d.write404(w) d.write404(w, r) return } diff, err := gr.Diff() if err != nil { d.write500(w) d.write500(w, r) log.Println(err) return }
-
@@ -130,7 +130,7 @@ func (d *deps) serveDiff(w http.ResponseWriter, r *http.Request) {func (d *deps) serveRefs(w http.ResponseWriter, r *http.Request) { gr, name, err := d.openRepository(r.PathValue("name"), "") if err != nil { d.write404(w) d.write404(w, r) return }
-
@@ -143,13 +143,13 @@ func (d *deps) serveRefs(w http.ResponseWriter, r *http.Request) {branches, err := gr.Branches() if err != nil { log.Println(err) d.write500(w) d.write500(w, r) return } mainBranch, err := gr.FindMainBranch(d.c.Repo.MainBranch) if err != nil { d.write500(w) d.write500(w, r) log.Println(err) return }
-
@@ -176,7 +176,7 @@ func (d *deps) serveStatic(w http.ResponseWriter, r *http.Request) {name := r.PathValue("file") name = filepath.Clean(name) if !filepath.IsLocal(name) { d.write404(w) d.write404(w, r) return }
-
-
-
@@ -13,20 +13,20 @@ func (d *deps) serveFileContent(w http.ResponseWriter, r *http.Request) {ref := r.PathValue("ref") gr, name, err := d.openRepository(r.PathValue("name"), ref) if err != nil { d.write404(w) d.write404(w, r) return } treePath := r.PathValue("rest") file, err := gr.File(treePath) if err != nil { d.write500(w) d.write500(w, r) return } contents, err := file.Contents() if err != nil { d.write500(w) d.write500(w, r) return }
-
@@ -61,14 +61,14 @@ func (d *deps) serveFileContent(w http.ResponseWriter, r *http.Request) {renderer := d.htmlRenderer(file) if renderer == nil { log.Printf("Requested HTML preview for %s/%s, but the filetype has no HTML renderer", name, treePath) d.write404(w) d.write404(w, r) return } html, err := renderer.Render([]byte(contents), newRepoLinkTransformer(name, ref)) if err != nil { log.Printf("Failed to render HTML preview: %s", err) d.write500(w) d.write500(w, r) return }
-
@@ -87,7 +87,7 @@ func (d *deps) serveFileContent(w http.ResponseWriter, r *http.Request) {return default: log.Printf("Got ?preview=%s, but not preview renderer is available for the type", previewType) d.write404(w) d.write404(w, r) return } }
-
@@ -95,7 +95,7 @@ func (d *deps) serveFileContent(w http.ResponseWriter, r *http.Request) {lc, err := countLines(strings.NewReader(contents)) if err != nil { log.Printf("Failed to count lines for %s: %s", r.URL.Path, err) d.write500(w) d.write500(w, r) return }
-
-
-
@@ -10,7 +10,7 @@ import (func (d *deps) serveIndex(w http.ResponseWriter, r *http.Request) { dirs, err := os.ReadDir(d.c.Repo.ScanPath) if err != nil { d.write500(w) d.write500(w, r) log.Printf("reading scan path: %s", err) return }
-
@@ -37,7 +37,7 @@ func (d *deps) serveIndex(w http.ResponseWriter, r *http.Request) {c, err := gr.LastCommit() if err != nil { d.write500(w) d.write500(w, r) log.Println(err) return }
-
-
-
@@ -13,7 +13,7 @@ func (d *deps) serveLog(w http.ResponseWriter, r *http.Request) {ref := r.PathValue("ref") gr, name, err := d.openRepository(r.PathValue("name"), ref) if err != nil { d.write404(w) d.write404(w, r) return }
-
@@ -31,7 +31,7 @@ func (d *deps) serveLog(w http.ResponseWriter, r *http.Request) {commits, page, err := gr.Commits(opts) if err != nil { d.write500(w) d.write500(w, r) log.Println(err) return }
-
-
-
@@ -11,20 +11,20 @@ import (func (d *deps) serveRepoIndex(w http.ResponseWriter, r *http.Request) { gr, name, err := d.openRepository(r.PathValue("name"), "") if err != nil { d.write404(w) d.write404(w, r) return } commits, _, err := gr.Commits(git.CommitsOptions{Limit: 3}) if err != nil { d.write500(w) d.write500(w, r) log.Println(err) return } mainBranch, err := gr.FindMainBranch(d.c.Repo.MainBranch) if err != nil { d.write500(w) d.write500(w, r) log.Println(err) return }
-