~sircmpwn/godocs.io

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH gddo v2] internal/source: Don't omit empty packages

Details
Message ID
<20210426093722.5963-1-me@adnano.co>
DKIM signature
pass
Download raw message
Patch: +43 -29
---
Same as the previous patch, except avoids uneccesary looping in
source.Get by exiting the loop if the parent directory exists.

 gddo-server/assets/templates/cmd.html       |  2 +-
 gddo-server/assets/templates/common.html    |  4 +--
 gddo-server/assets/templates/graph.html     |  2 +-
 gddo-server/assets/templates/importers.html |  2 +-
 gddo-server/assets/templates/imports.html   |  2 +-
 gddo-server/assets/templates/tools.html     |  4 +--
 gddo-server/crawl.go                        |  6 +++++
 gddo-server/main.go                         | 13 +---------
 gddo-server/template.go                     |  9 -------
 internal/source/get.go                      | 28 +++++++++++++++++++++
 10 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/gddo-server/assets/templates/cmd.html b/gddo-server/assets/templates/cmd.html
index bbdec23..4dd430d 100644
--- a/gddo-server/assets/templates/cmd.html
+++ b/gddo-server/assets/templates/cmd.html
@@ -2,7 +2,7 @@

{{define "Body"}}
  {{template "ProjectNav" $}}
  <h2>Command {{$.PageName}}</h2>
  <h2>Command {{$.Name}}</h2>
  {{$.Doc|comment}}
  {{template "PkgFiles" $}}
  {{template "PkgCmdFooter" $}}
diff --git a/gddo-server/assets/templates/common.html b/gddo-server/assets/templates/common.html
index a8b5141..1ac7ad1 100644
--- a/gddo-server/assets/templates/common.html
+++ b/gddo-server/assets/templates/common.html
@@ -48,9 +48,9 @@
{{end}}

{{define "PkgCmdHeader"}}
  <title>{{.PageName}} - godocs.io</title>
  <title>{{.Name}} - godocs.io</title>
  {{if .Synopsis}}
    <meta property="og:title" content="{{if .IsCommand}}Command{{else}}Package{{end}} {{.PageName}}">
    <meta property="og:title" content="{{if .IsCommand}}Command{{else}}Package{{end}} {{.Name}}">
    <meta name="description" content="{{.Synopsis}}">
    <meta property="og:description" content="{{.Synopsis}}">
  {{end}}
diff --git a/gddo-server/assets/templates/graph.html b/gddo-server/assets/templates/graph.html
index 3d53e34..f987169 100644
--- a/gddo-server/assets/templates/graph.html
+++ b/gddo-server/assets/templates/graph.html
@@ -1,6 +1,6 @@
{{define "ROOT"}}<!DOCTYPE html><html lang="en">
    <head>
      <title>{{.PageName}} graph - godocs.io</title>
      <title>{{.Name}} graph - godocs.io</title>
      <meta name="robots" content="NOINDEX, NOFOLLOW">
      <link href="{{staticPath "/-/bootstrap.min.css"}}" rel="stylesheet">
      <link href="{{staticPath "/-/site.css"}}" rel="stylesheet">
diff --git a/gddo-server/assets/templates/importers.html b/gddo-server/assets/templates/importers.html
index 124c975..95b7fc3 100644
--- a/gddo-server/assets/templates/importers.html
+++ b/gddo-server/assets/templates/importers.html
@@ -1,4 +1,4 @@
{{define "Head"}}<title>{{.PageName}} importers - godocs.io</title><meta name="robots" content="NOINDEX, NOFOLLOW">{{end}}
{{define "Head"}}<title>{{.Name}} importers - godocs.io</title><meta name="robots" content="NOINDEX, NOFOLLOW">{{end}}

{{define "Body"}}
  {{template "ProjectNav" $}}
diff --git a/gddo-server/assets/templates/imports.html b/gddo-server/assets/templates/imports.html
index 4b8058b..9ffa712 100644
--- a/gddo-server/assets/templates/imports.html
+++ b/gddo-server/assets/templates/imports.html
@@ -1,4 +1,4 @@
{{define "Head"}}<title>{{.PageName}} imports - godocs.io</title><meta name="robots" content="NOINDEX, NOFOLLOW">{{end}}
{{define "Head"}}<title>{{.Name}} imports - godocs.io</title><meta name="robots" content="NOINDEX, NOFOLLOW">{{end}}

{{define "Body"}}
  {{template "ProjectNav" $}}
diff --git a/gddo-server/assets/templates/tools.html b/gddo-server/assets/templates/tools.html
index 6a94183..49deefe 100644
--- a/gddo-server/assets/templates/tools.html
+++ b/gddo-server/assets/templates/tools.html
@@ -1,8 +1,8 @@
{{define "Head"}}<title>{{.PageName}} tools - godocs.io</title><meta name="robots" content="NOINDEX, NOFOLLOW">{{end}}
{{define "Head"}}<title>{{.Name}} tools - godocs.io</title><meta name="robots" content="NOINDEX, NOFOLLOW">{{end}}

{{define "Body"}}
  {{template "ProjectNav" $}}
  <h2>Tools for {{$.PageName}}</h2>
  <h2>Tools for {{$.Name}}</h2>

  <h3>Badge</h3>

diff --git a/gddo-server/crawl.go b/gddo-server/crawl.go
index 730c877..afeff81 100644
--- a/gddo-server/crawl.go
+++ b/gddo-server/crawl.go
@@ -11,6 +11,7 @@ import (
	"errors"
	"go/build"
	"log"
	"path"
	"time"

	"git.sr.ht/~sircmpwn/gddo/internal/database"
@@ -102,6 +103,11 @@ func (s *server) crawl(ctx context.Context, modulePath string) (database.Module,
			log.Println(err)
			continue
		}
		if len(pkg.Files) == 0 {
			pdoc.ImportPath = pkg.Path
			_, name := path.Split(pkg.Path)
			pdoc.Name = name
		}
		if err := s.db.PutPackage(ctx, modulePath, seriesPath, info.Version, info.Time, pdoc); err != nil {
			log.Println(err)
			continue
diff --git a/gddo-server/main.go b/gddo-server/main.go
index a0b8235..35f8075 100644
--- a/gddo-server/main.go
+++ b/gddo-server/main.go
@@ -153,18 +153,7 @@ func (s *server) servePackage(resp http.ResponseWriter, req *http.Request) error
	importPath := strings.TrimPrefix(req.URL.Path, "/")
	mod, pkg, pdoc, err := s.GetDoc(req.Context(), importPath)
	if err != nil {
		if mod != nil && errors.Is(err, proxy.ErrNotFound) {
			pkg = &database.Package{
				ImportPath: importPath,
				ModulePath: mod.ModulePath,
				Version:    mod.Version,
			}
			pdoc = &doc.Package{
				ImportPath: importPath,
			}
		} else {
			return err
		}
		return err
	}

	var meta *source.Meta
diff --git a/gddo-server/template.go b/gddo-server/template.go
index 3dff5a2..a1836d4 100644
--- a/gddo-server/template.go
+++ b/gddo-server/template.go
@@ -15,7 +15,6 @@ import (
	"io"
	"net/http"
	"net/url"
	"path"
	"path/filepath"
	"reflect"
	"regexp"
@@ -112,14 +111,6 @@ func (pdoc *Package) SourceLink(pos doc.Pos, text string, textOnlyOK bool) htemp
		htemp.HTMLEscapeString(text)))
}

func (pdoc *Package) PageName() string {
	if pdoc.Name != "" && !pdoc.IsCommand {
		return pdoc.Name
	}
	_, name := path.Split(pdoc.ImportPath)
	return name
}

func (pdoc *Package) addExamples(obj interface{}, export, method string, examples []*doc.Example) {
	label := export
	id := export
diff --git a/internal/source/get.go b/internal/source/get.go
index 052cc4a..3938b74 100644
--- a/internal/source/get.go
+++ b/internal/source/get.go
@@ -105,6 +105,34 @@ func parsePackages(zip *zip.Reader, modulePath, version string) ([]*Package, err
			return nil, err
		}

		// Add parent packages if they don't exist
		dir := path.Dir(pkgPath)
		for {
			var stop bool
			if dir == "." {
				dir = ""
				stop = true
			}
			_, ok := pkgsMap[dir]
			if ok {
				break
			} else {
				var importPath string
				if modulePath == stdlib.ModulePath {
					importPath = dir
				} else {
					importPath = path.Join(modulePath, dir)
				}
				pkgsMap[dir] = &Package{
					Path: importPath,
				}
			}
			if stop {
				break
			}
			dir = path.Dir(dir)
		}

		// Add package if it does not exist
		pkg, ok := pkgsMap[pkgPath]
		if !ok {
-- 
2.31.1
Details
Message ID
<CAXKJKHSAKHF.2EEKVBMSV47HT@zoidberg>
In-Reply-To
<20210426093722.5963-1-me@adnano.co> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
On Mon Apr 26, 2021 at 11:37 CET, Adnan Maolood wrote:
> ---
[...]

> diff --git a/gddo-server/crawl.go b/gddo-server/crawl.go
> index 730c877..afeff81 100644
> --- a/gddo-server/crawl.go
> +++ b/gddo-server/crawl.go
> @@ -11,6 +11,7 @@ import (
> "errors"
> "go/build"
> "log"
> + "path"
> "time"
>  
> "git.sr.ht/~sircmpwn/gddo/internal/database"
> @@ -102,6 +103,11 @@ func (s *server) crawl(ctx context.Context,
> modulePath string) (database.Module,
> log.Println(err)
> continue
> }
> + if len(pkg.Files) == 0 {
> + pdoc.ImportPath = pkg.Path
> + _, name := path.Split(pkg.Path)
> + pdoc.Name = name
> + }

perhaps use path.Base instead of path.Split ?

-s
Details
Message ID
<CAXKX6CHV7DE.3IOHWBJWZO79X@nitro>
In-Reply-To
<CAXKJKHSAKHF.2EEKVBMSV47HT@zoidberg> (view parent)
DKIM signature
pass
Download raw message
On Mon Apr 26, 2021 at 6:04 AM EDT, Sebastien Binet wrote:
> perhaps use path.Base instead of path.Split ?

I've sent a new patch which makes this modification. Note that the
original code used path.Split.
Reply to thread Export thread (mbox)