commit 566cb9188197177956e9272ef885bd9780e6b42a
parent 446318893cc91640196a5fbd5719e5e6c4bfb967
Author: gearsix <gearsix@tuta.io>
Date: Tue, 18 Jan 2022 23:42:47 +0000
ran gofmt -w -s
Diffstat:
8 files changed, 44 insertions(+), 47 deletions(-)
diff --git a/config_test.go b/config_test.go
@@ -2,8 +2,8 @@ package main
import (
"fmt"
- "path/filepath"
"os"
+ "path/filepath"
"testing"
)
diff --git a/copy.go b/copy.go
@@ -7,12 +7,12 @@ package main
int copyf(const char *src, const char *dst)
{
int ret = EXIT_FAILURE;
-
+
FILE *srcf, *dstf;
if ((!(srcf = fopen(src, "rb"))) ||
(!(dstf = fopen(dst, "wb"))))
goto ABORT;
-
+
fseek(srcf, 0, SEEK_END);
size_t siz = ftell(srcf);
rewind(srcf);
@@ -29,7 +29,7 @@ int copyf(const char *src, const char *dst)
}
} while (!feof(srcf));
if (total == siz) ret = EXIT_SUCCESS;
-
+
ABORT:
if (srcf) fclose(srcf);
if (dstf) fclose(dstf);
@@ -39,8 +39,8 @@ ABORT:
import "C"
import (
"fmt"
- "path/filepath"
"os"
+ "path/filepath"
"unsafe"
)
diff --git a/copy_test.go b/copy_test.go
@@ -32,4 +32,3 @@ func TestCopyFile(test *testing.T) {
test.Fatalf("copied data (%s) does not match source (%s)", buf, data)
}
}
-
diff --git a/page.go b/page.go
@@ -10,12 +10,12 @@ import (
goldmarkhtml "github.com/yuin/goldmark/renderer/html"
"io"
"io/fs"
- "time"
"notabug.org/gearsix/suti"
"os"
"path/filepath"
- "strings"
"sort"
+ "strings"
+ "time"
)
const timefmt = "2006-01-02"
@@ -50,10 +50,10 @@ func BuildSitemap(pages []Page) []Page {
}
p.Nav.All = append(p.Nav.All, &pages[j])
- if p.Nav.Parent == nil && ppdepth == pdepth - 1 && strings.Contains(p.Path, pp.Path) {
+ if p.Nav.Parent == nil && ppdepth == pdepth-1 && strings.Contains(p.Path, pp.Path) {
p.Nav.Parent = &pages[j]
}
- if ppdepth == pdepth + 1 && strings.Contains(pp.Path, p.Path) {
+ if ppdepth == pdepth+1 && strings.Contains(pp.Path, p.Path) {
p.Nav.Children = append(p.Nav.Children, &pages[j])
}
}
@@ -103,13 +103,13 @@ func lastFileMod(fpath string) time.Time {
}
func titleFromPath(path string) (title string) {
- if title = filepath.Base(path); title == "/" {
- title = "Home"
- }
- title = strings.TrimSuffix(title, filepath.Ext(title))
- title = strings.ReplaceAll(title, "-", " ")
- title = strings.Title(title)
- return
+ if title = filepath.Base(path); title == "/" {
+ title = "Home"
+ }
+ title = strings.TrimSuffix(title, filepath.Ext(title))
+ title = strings.ReplaceAll(title, "-", " ")
+ title = strings.Title(title)
+ return
}
var contentExts = [6]string{
@@ -300,7 +300,7 @@ func (p *Page) NewContentFromFile(fpath string) (err error) {
if filepath.Ext(fpath) == lang {
switch lang {
case "":
- body = "<pre>"+string(buf)+"</pre>"
+ body = "<pre>" + string(buf) + "</pre>"
case ".txt":
body = convertTextToHTML(bytes.NewReader(buf))
case ".md":
diff --git a/page_test.go b/page_test.go
@@ -2,11 +2,11 @@ package main
import (
"fmt"
- "path/filepath"
- "os"
- "time"
"notabug.org/gearsix/suti"
+ "os"
+ "path/filepath"
"testing"
+ "time"
)
// helper functions
@@ -138,11 +138,11 @@ func TestBuildSitemap(test *testing.T) {
var err error
/*
- writef := func(path, data string) {
- if err == nil {
- err = os.WriteFile(path, []byte(data), 0644)
+ writef := func(path, data string) {
+ if err == nil {
+ err = os.WriteFile(path, []byte(data), 0644)
+ }
}
- }
*/
tdir := test.TempDir()
// TODO write files to pages dir
@@ -241,11 +241,11 @@ func TestNewContentFromFile(test *testing.T) {
test.Parallel()
var err error
- contents := map[string]string {
- "txt": `test`,
- "md": "**test**\ntest",
- "gfm": "**test**\ntest",
- "cm": "**test**",
+ contents := map[string]string{
+ "txt": `test`,
+ "md": "**test**\ntest",
+ "gfm": "**test**\ntest",
+ "cm": "**test**",
"html": `<b>test</b>`,
}
@@ -275,7 +275,7 @@ func TestCopyAssets(test *testing.T) {
var err error
srcDir := test.TempDir()
- src := []string{"1","2","3","4"}
+ src := []string{"1", "2", "3", "4"}
for _, fname := range src {
p.Assets = append(p.Assets, fname)
@@ -290,7 +290,7 @@ func TestCopyAssets(test *testing.T) {
test.Fatal("CopyAssets failed", err)
}
for _, fname := range src {
- if _, err := os.Stat(dstDir+"/"+fname); err != nil {
+ if _, err := os.Stat(dstDir + "/" + fname); err != nil {
test.Fatal("missing file", dstDir+"/"+fname)
}
}
@@ -320,4 +320,3 @@ func TestBuild(test *testing.T) {
test.Fatalf("invalid result parsed: '%s', expected: 'Test p'", string(fbuf))
}
}
-
diff --git a/pagr.go b/pagr.go
@@ -1,15 +1,15 @@
package main
import (
- "fmt"
"flag"
+ "fmt"
"io/fs"
+ "log"
+ "notabug.org/gearsix/suti"
"os"
+ "path/filepath"
"strings"
"sync"
- "path/filepath"
- "log"
- "notabug.org/gearsix/suti"
)
const Name = "pagr"
@@ -20,7 +20,7 @@ var verbose bool
var ilog = log.New(os.Stdout, "", 0)
var elog = log.New(os.Stderr, "", 0)
-func vlog (fmt string, args ...interface{}) {
+func vlog(fmt string, args ...interface{}) {
if verbose {
ilog.Printf(fmt, args...)
}
diff --git a/template.go b/template.go
@@ -1,10 +1,10 @@
package main
import (
- "path/filepath"
"io/fs"
- "strings"
"notabug.org/gearsix/suti"
+ "path/filepath"
+ "strings"
)
// DefaultTemplateName provides the default name for the template used
@@ -34,16 +34,15 @@ func LoadTemplateDir(dir string) (templates []suti.Template, err error) {
return e
}
- for t, _ := range templatePaths {
+ for t := range templatePaths {
if strings.Contains(path, filepath.Dir(t)) &&
filepath.Ext(t) == filepath.Ext(path) {
- templatePaths[t] = append(templatePaths[t], path)
- }
+ templatePaths[t] = append(templatePaths[t], path)
+ }
}
return e
})
-
if err == nil {
var t suti.Template
for rootPath, partialPaths := range templatePaths {
diff --git a/template_test.go b/template_test.go
@@ -2,8 +2,8 @@ package main
import (
"fmt"
- "path/filepath"
"os"
+ "path/filepath"
"testing"
)
@@ -21,7 +21,7 @@ func TestLoadTemplateDir(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if len(tmpls) != len(templates) * 2 { // * 2 for partials
+ if len(tmpls) != len(templates)*2 { // * 2 for partials
t.Fatalf("number of returned templates is %d (should be %d)",
len(tmpls), len(templates))
}
@@ -30,7 +30,7 @@ func TestLoadTemplateDir(t *testing.T) {
var templates = map[string]string{ // [ext]template
"tmpl": "{{.Contents}}",
"hmpl": "{{.Contents}}",
- "mst": "{{Contents}}",
+ "mst": "{{Contents}}",
}
func createProjectTemplates(dir string) error {