mirror of
https://github.com/tiennm99/hugoThemesSiteBuilder.git
synced 2026-10-14 18:18:36 +00:00
Fix path html_url etc. path logic for modules with major versions in path
Updates #454
This commit is contained in:
3 files changed
+25
-4
No files matched your search
@@ -393,7 +393,7 @@ func (t *theme) toFrontMatter() map[string]interface{} {
|
||||
htmlURL = t.ghRepo.HTMLURL
|
||||
} else {
|
||||
// Gitlab etc., assume the path is the base of the URL.
|
||||
htmlURL = fmt.Sprintf("https://%s", t.m.Path)
|
||||
htmlURL = fmt.Sprintf("https://%s", t.m.PathRepo())
|
||||
}
|
||||
|
||||
var expiryDate time.Time
|
||||
|
||||
+15
-3
@@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -327,10 +328,15 @@ type Module struct {
|
||||
Meta map[string]interface{} `json:"meta"`
|
||||
}
|
||||
|
||||
func (m Module) PathWithoutVersion() string {
|
||||
return PathWithoutVersion(m.Path)
|
||||
}
|
||||
|
||||
// PathRepo returns the root path to the repository.
|
||||
func (m Module) PathRepo() string {
|
||||
slashCount := 0
|
||||
idx := strings.IndexFunc(m.Path, func(r rune) bool {
|
||||
p := m.PathWithoutVersion()
|
||||
idx := strings.IndexFunc(p, func(r rune) bool {
|
||||
if r == '/' {
|
||||
slashCount++
|
||||
}
|
||||
@@ -338,10 +344,10 @@ func (m Module) PathRepo() string {
|
||||
})
|
||||
|
||||
if slashCount < 3 {
|
||||
return m.Path
|
||||
return p
|
||||
}
|
||||
|
||||
return m.Path[:idx]
|
||||
return p[:idx]
|
||||
}
|
||||
|
||||
// HugoVersion holds Hugo binary version requirements for a module.
|
||||
@@ -353,6 +359,12 @@ type HugoVersion struct {
|
||||
|
||||
type ModulesMap map[string]Module
|
||||
|
||||
var pathVersionRe = regexp.MustCompile(`/v\d+$`)
|
||||
|
||||
func PathWithoutVersion(s string) string {
|
||||
return pathVersionRe.ReplaceAllString(s, "")
|
||||
}
|
||||
|
||||
func setEnvVar(vars *[]string, key, value string) {
|
||||
for i := range *vars {
|
||||
if strings.HasPrefix((*vars)[i], key+"=") {
|
||||
|
||||
@@ -15,5 +15,14 @@ func TestModule(t *testing.T) {
|
||||
c.Assert(Module{Path: "github.com/a/b"}.PathRepo(), qt.Equals, "github.com/a/b")
|
||||
c.Assert(Module{Path: "github.com/a"}.PathRepo(), qt.Equals, "github.com/a")
|
||||
c.Assert(Module{Path: "github.com"}.PathRepo(), qt.Equals, "github.com")
|
||||
c.Assert(Module{Path: "github.com/a/v2"}.PathRepo(), qt.Equals, "github.com/a")
|
||||
})
|
||||
}
|
||||
|
||||
func TestPathWithoutVersion(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
c.Assert(PathWithoutVersion("github.com/gohugoio/hugo/v3"), qt.Equals, "github.com/gohugoio/hugo")
|
||||
c.Assert(PathWithoutVersion("github.com/gohugoio/hugo/v2"), qt.Equals, "github.com/gohugoio/hugo")
|
||||
c.Assert(PathWithoutVersion("github.com/gohugoio/hugo"), qt.Equals, "github.com/gohugoio/hugo")
|
||||
}
|
||||
Reference in new issue
Block a user