diff --git a/distribusi.go b/distribusi.go index a84799c..273ab58 100644 --- a/distribusi.go +++ b/distribusi.go @@ -102,6 +102,39 @@ var htmlBody = ` %s", + "generic": "
%s
", + }, + "image": { + "thumbnail": "
%s
", + "generic": "
%s
", + }, + "application": { + "pdf": "", + }, + "audio": { + "generic": "", + }, + "video": { + "generic": "", + }, + "unknown": { + "generic": "%s", + }, +} + // main is the command-line entrypoint. func main() { if Version == "" { @@ -552,10 +585,11 @@ func getHref(c *cli.Context, fpath string, mtype string) (bool, string, error) { if err != nil { return unknown, href, err } + if stype == "html" { - href = fmt.Sprintf("
%s
", fname, trimFinalNewline(fcontents)) + href = fmt.Sprintf(htmlTags[ftype][stype], fname, trimFinalNewline(fcontents)) } else { - href = fmt.Sprintf("
%s
", trimFinalNewline(fcontents)) + href = fmt.Sprintf(htmlTags[ftype]["generic"], trimFinalNewline(fcontents)) } } else if ftype == "image" { caption, err := getCaption(c, fpath) @@ -564,33 +598,30 @@ func getHref(c *cli.Context, fpath string, mtype string) (bool, string, error) { } if stype == "gif" { - href = fmt.Sprintf("
%s
", fname, stype, fname, caption) + href = fmt.Sprintf(htmlTags[ftype]["generic"], fname, stype, fname, caption) } else { thumb, err := genThumb(c, fpath, caption) if err != nil { logrus.Debugf("failed to generate thumbnail for %s, showing original image", fpath) - href = fmt.Sprintf("
%s
", fname, stype, fname, caption) + href = fmt.Sprintf(htmlTags[ftype]["generic"], fname, stype, fname, caption) } else { - href = fmt.Sprintf( - "
%s
", - fname, thumb, caption, - ) + href = fmt.Sprintf(htmlTags[ftype]["thumbnail"], fname, thumb, caption) } } } else if ftype == "application" { if stype == "pdf" { - href = fmt.Sprintf("", fname, fname) + href = fmt.Sprintf(htmlTags[ftype][stype], fname, fname) } else { unknown = true - href = fmt.Sprintf("%s", stype, fname, fname) + href = fmt.Sprintf(htmlTags["unknown"]["generic"], stype, fname, fname) } } else if ftype == "audio" { - href = fmt.Sprintf("", fname, stype) + href = fmt.Sprintf(htmlTags[ftype]["generic"], fname, stype) } else if ftype == "video" { - href = fmt.Sprintf("", fname, stype) + href = fmt.Sprintf(htmlTags[ftype]["generic"], fname, stype) } else { unknown = true - href = fmt.Sprintf("%s", stype, fname, fname) + href = fmt.Sprintf(htmlTags["unknown"]["generic"], stype, fname, fname) } logrus.Debugf("generated href for %s: %s", fname, href)