|
|
@ -229,7 +229,7 @@ func distribusify(c *cli.Context, root string, ignore []string) error { |
|
|
|
if err := filepath.Walk(root, func(fpath string, finfo os.FileInfo, err error) error { |
|
|
|
|
|
|
|
if skip := shouldSkip(c, fpath, ignore); skip { |
|
|
|
return filepath.SkipDir |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
var html []string |
|
|
@ -245,11 +245,8 @@ func distribusify(c *cli.Context, root string, ignore []string) error { |
|
|
|
|
|
|
|
contents, err := ioutil.ReadDir(absPath) |
|
|
|
if err != nil { |
|
|
|
if strings.Contains(err.Error(), "permission denied") { |
|
|
|
return filepath.SkipDir |
|
|
|
} |
|
|
|
|
|
|
|
return err |
|
|
|
logrus.Debugf("unable to read %s", absPath) |
|
|
|
return filepath.SkipDir |
|
|
|
} |
|
|
|
|
|
|
|
for _, content := range contents { |
|
|
@ -259,10 +256,11 @@ func distribusify(c *cli.Context, root string, ignore []string) error { |
|
|
|
if content.Name() == "index.html" { |
|
|
|
file, err := os.ReadFile(path.Join(absPath, content.Name())) |
|
|
|
if err != nil { |
|
|
|
return filepath.SkipDir |
|
|
|
logrus.Debugf("unable to read %s, skipping", content.Name()) |
|
|
|
continue |
|
|
|
} |
|
|
|
if strings.Contains(string(file), generatedInDistribusi) { |
|
|
|
return filepath.SkipDir |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
files = append(files, path.Join(absPath, content.Name())) |
|
|
@ -309,24 +307,28 @@ func distribusify(c *cli.Context, root string, ignore []string) error { |
|
|
|
|
|
|
|
mtype, err := getMtype(file) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
logrus.Debugf("failed to read mimetype of %s", file) |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
unknown, href, err := getHref(c, file, mtype) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
logrus.Debugf("failed to generate href for %s", file) |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
div, err := mkDiv(c, mtype, href, fname, unknown) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
logrus.Debugf("failed to generate div for %s", file) |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
html = append(html, div) |
|
|
|
} |
|
|
|
|
|
|
|
if err := writeIndex(absPath, html, c.String("css")); err != nil { |
|
|
|
return err |
|
|
|
logrus.Debugf("unable to generated %s, skipping", path.Join(absPath, "index.html")) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
allDirs = append(allDirs, strings.Join(dirs, " ")) |
|
|
@ -377,7 +379,7 @@ func getMtype(fpath string) (string, error) { |
|
|
|
func genThumb(c *cli.Context, fpath, caption string) (string, error) { |
|
|
|
knownFailureExts := []string{".ico", ".svg", ".xcf"} |
|
|
|
if sliceContains(knownFailureExts, filepath.Ext(fpath)) { |
|
|
|
return "", nil |
|
|
|
return "", fmt.Errorf("unable to generate thumbnail for %s", fpath) |
|
|
|
} |
|
|
|
|
|
|
|
imgSrc, err := imaging.Open(fpath, imaging.AutoOrientation(true)) |
|
|
@ -557,7 +559,7 @@ func writeIndex(fpath string, html []string, styles string) error { |
|
|
|
if _, err := os.Stat(absPath); !os.IsNotExist(err) { |
|
|
|
contents, err := os.ReadFile(absPath) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
body = fmt.Sprintf(htmlBody, generatedInDistribusi, contents, strings.Join(html, "\n")) |
|
|
@ -570,20 +572,24 @@ func writeIndex(fpath string, html []string, styles string) error { |
|
|
|
if _, err := os.Stat(HTMLPath); err != nil { |
|
|
|
if os.IsNotExist(err) { |
|
|
|
if err := ioutil.WriteFile(HTMLPath, contents, 0644); err != nil { |
|
|
|
return err |
|
|
|
logrus.Debugf("unable to write %s, skipping", HTMLPath) |
|
|
|
return nil |
|
|
|
} |
|
|
|
} else { |
|
|
|
return err |
|
|
|
logrus.Debugf("unable to read %s, skipping", HTMLPath) |
|
|
|
return nil |
|
|
|
} |
|
|
|
} else { |
|
|
|
file, err := os.ReadFile(HTMLPath) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
logrus.Debugf("unable to read %s, skipping", HTMLPath) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
if strings.Contains(string(file), generatedInDistribusi) { |
|
|
|
if err := ioutil.WriteFile(HTMLPath, contents, 0644); err != nil { |
|
|
|
return err |
|
|
|
logrus.Debugf("unable to write %s, skipping", HTMLPath) |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|