Create default link and image render hooks

Fixes #11933
This commit is contained in:
Bjørn Erik Pedersen
2024-01-30 11:43:20 +01:00
parent 80595bbe3e
commit 5b7cb258ec
15 changed files with 229 additions and 42 deletions

View File

@@ -185,42 +185,15 @@ func TestRace() error {
// Run gofmt linter
func Fmt() error {
if !isGoLatest() {
if !isGoLatest() && !isUnix() {
return nil
}
pkgs, err := hugoPackages()
s, err := sh.Output("./check_gofmt.sh")
if err != nil {
return err
}
failed := false
first := true
for _, pkg := range pkgs {
files, err := filepath.Glob(filepath.Join(pkg, "*.go"))
if err != nil {
return nil
}
for _, f := range files {
// gofmt doesn't exit with non-zero when it finds unformatted code
// so we have to explicitly look for output, and if we find any, we
// should fail this target.
s, err := sh.Output("gofmt", "-l", f)
if err != nil {
fmt.Printf("ERROR: running gofmt on %q: %v\n", f, err)
failed = true
}
if s != "" {
if first {
fmt.Println("The following files are not gofmt'ed:")
first = false
}
failed = true
fmt.Println(s)
}
}
}
if failed {
return errors.New("improperly formatted go files")
fmt.Println(s)
return fmt.Errorf("gofmt needs to be run: %s", err)
}
return nil
}
@@ -332,6 +305,10 @@ func isGoLatest() bool {
return strings.Contains(runtime.Version(), "1.21")
}
func isUnix() bool {
return runtime.GOOS != "windows"
}
func isCI() bool {
return os.Getenv("CI") != ""
}