diff options
Diffstat (limited to 'pkg/html')
| -rw-r--r-- | pkg/html/autoindex.go | 68 | ||||
| -rw-r--r-- | pkg/html/notfound.go | 25 |
2 files changed, 93 insertions, 0 deletions
diff --git a/pkg/html/autoindex.go b/pkg/html/autoindex.go new file mode 100644 index 0000000..4c31134 --- /dev/null +++ b/pkg/html/autoindex.go @@ -0,0 +1,68 @@ +package html + +import ( + "fmt" + "strconv" + + . "github.com/LMBishop/scrapbook/web/skeleton" + . "maragu.dev/gomponents" + . "maragu.dev/gomponents/html" +) + +type File struct { + Name string + IsDir bool + Size int64 + Mtime int +} + +func IndexPage(dir string, err bool, files []File) Node { + return Page("Index of "+dir, + H1(Text("Index of "+dir)), + + Div( + Class("table files-table"), + Group{ + Span( + Class("header name"), + Text("Name"), + ), + Span( + Class("header size"), + Text("Size"), + ), + Span( + Class("header last-modified"), + Text("Last modified"), + ), + }, + + If(files != nil, Map(files, func(file File) Node { + var fileName string + if file.IsDir { + fileName = file.Name + "/" + } else { + fileName = file.Name + } + return Group{ + A( + Class("name"), + Href(fileName), + Text(fileName), + ), + Span( + Class("size"), + If(file.IsDir, Text("--")), + If(!file.IsDir, Text(strconv.FormatInt(file.Size, 10)+" bytes")), + ), + Span( + Class("last-modified"), + Text("--"), + ), + } + })), + ), + + If(err, AlertError(fmt.Sprintf("Failed to list directory"))), + ) +} diff --git a/pkg/html/notfound.go b/pkg/html/notfound.go new file mode 100644 index 0000000..ceb521f --- /dev/null +++ b/pkg/html/notfound.go @@ -0,0 +1,25 @@ +package html + +import ( + "fmt" + + . "github.com/LMBishop/scrapbook/web/skeleton" + . "maragu.dev/gomponents" + . "maragu.dev/gomponents/html" +) + +func NotFoundUrlPage(url, host string) Node { + return Page("Page not found", + H1(Text("Page not found")), + + P(Text(fmt.Sprintf("The URL %s could not be found on site %s", url, host))), + ) +} + +func NotFoundSitePage(host string) Node { + return Page("Site not found", + H1(Text("Site not found")), + + P(Text(fmt.Sprintf("The site %s is unknown", host))), + ) +} |
