diff --git a/Dockerfile b/Dockerfile index e4f8b49..5678d3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:alpine as builder +FROM golang:1.26.4-alpine as builder ENV GO111MODULE on COPY . $GOPATH/src/github.com/sourcegraph/docsite WORKDIR $GOPATH/src/github.com/sourcegraph/docsite diff --git a/cmd/docsite/cmd.go b/cmd/docsite/cmd.go index d83e6b2..ab404e7 100644 --- a/cmd/docsite/cmd.go +++ b/cmd/docsite/cmd.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "slices" "strings" "text/template" @@ -42,12 +43,7 @@ func (c *command) matches(name string) bool { if name == c.FlagSet.Name() { return true } - for _, alias := range c.aliases { - if name == alias { - return true - } - } - return false + return slices.Contains(c.aliases, name) } // commander represents a top-level command with subcommands. diff --git a/cmd/docsite/site.go b/cmd/docsite/site.go index 1e15b90..35beb16 100644 --- a/cmd/docsite/site.go +++ b/cmd/docsite/site.go @@ -151,7 +151,7 @@ func addRedirectsFromAssets(site *docsite.Site) error { if err != nil && !os.IsNotExist(err) { return err } - for _, line := range bytes.Split(raw, []byte("\n")) { + for line := range bytes.SplitSeq(raw, []byte("\n")) { line = bytes.TrimSpace(line) if len(line) == 0 || line[0] == '#' { continue diff --git a/funcs.go b/funcs.go index 7cf0cd0..28c1ecf 100644 --- a/funcs.go +++ b/funcs.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "maps" "net/url" "strings" "text/template" @@ -108,9 +109,7 @@ func createMarkdownFuncs(site *Site) markdown.FuncMap { return string(doc.HTML), nil }, } - for name, f := range testMarkdownFuncs { - m[name] = f - } + maps.Copy(m, testMarkdownFuncs) return m } diff --git a/go.mod b/go.mod index 55bca28..44149c2 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -go 1.21 - -toolchain go1.23.2 +go 1.26.4 diff --git a/handler.go b/handler.go index 8ec2dbd..925fae3 100644 --- a/handler.go +++ b/handler.go @@ -20,13 +20,13 @@ func shouldRedirectVersion(version string) bool { if len(matches) < 3 { return false } - + major, err1 := strconv.Atoi(matches[1]) minor, err2 := strconv.Atoi(matches[2]) if err1 != nil || err2 != nil { return false } - + return major > 5 || (major == 5 && minor >= 2) } @@ -145,7 +145,7 @@ func (s *Site) Handler() http.Handler { urlPath = r.URL.Path[1+end+1:] contentVersion = r.URL.Path[1 : 1+end] } - + // Redirect versions ≥ 5.2 to new docs domain with path preservation version := "@" + contentVersion if shouldRedirectVersion(version) { @@ -156,7 +156,7 @@ func (s *Site) Handler() http.Handler { http.Redirect(w, r, newURL, http.StatusPermanentRedirect) return } - + r = requestShallowCopyWithURLPath(r, urlPath) } @@ -196,8 +196,8 @@ func (s *Site) Handler() http.Handler { filePath, fileData, err := resolveAndReadAll(content, r.URL.Path) if err == nil { // Strip trailing slashes for consistency. - if strings.HasSuffix(r.URL.Path, "/") { - http.Redirect(w, r, path.Join(basePath, strings.TrimSuffix(r.URL.Path, "/")), http.StatusMovedPermanently) + if before, ok := strings.CutSuffix(r.URL.Path, "/"); ok { + http.Redirect(w, r, path.Join(basePath, before), http.StatusMovedPermanently) return } diff --git a/internal/search/excerpt.go b/internal/search/excerpt.go index 218d957..e0cb182 100644 --- a/internal/search/excerpt.go +++ b/internal/search/excerpt.go @@ -29,10 +29,7 @@ func excerpt(text []byte, start, end, maxChars int) []byte { } if index := bytes.LastIndexAny(text[origEnd:end], breakChars); index != -1 { - end = origEnd + index + 1 - if end > len(text) { - end = len(text) - } + end = min(origEnd+index+1, len(text)) } return bytes.TrimSpace(text[start:end]) diff --git a/markdown/extender.go b/markdown/extender.go index 6fb9bdf..18b3d04 100644 --- a/markdown/extender.go +++ b/markdown/extender.go @@ -115,7 +115,7 @@ func (r *nodeRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) { var val []byte l := n.Segments.Len() - for i := 0; i < l; i++ { + for i := range l { segment := n.Segments.At(i) val = append(val, segment.Value(source)...) }