Improve serach function with quick suggestions
This commit is contained in:
@@ -28,7 +28,6 @@ func initMarkdown(root string) {
|
||||
)
|
||||
}
|
||||
|
||||
type crumb struct{ Name, URL string }
|
||||
type entry struct {
|
||||
Icon template.HTML
|
||||
Name, URL, Meta string
|
||||
@@ -36,7 +35,7 @@ type entry struct {
|
||||
|
||||
type pageData struct {
|
||||
Title string
|
||||
Crumbs []crumb
|
||||
ParentURL string
|
||||
CanEdit bool
|
||||
EditMode bool
|
||||
IsRoot bool
|
||||
@@ -56,6 +55,7 @@ type pageSettings struct {
|
||||
}
|
||||
|
||||
var (
|
||||
iconUp = readIcon("up")
|
||||
iconFolder = readIcon("folder")
|
||||
iconDoc = readIcon("doc")
|
||||
iconImage = readIcon("image")
|
||||
@@ -155,7 +155,20 @@ func listEntries(fsPath, urlPath string) []entry {
|
||||
return strings.ToLower(files[i].Name) < strings.ToLower(files[j].Name)
|
||||
})
|
||||
|
||||
return append(folders, files...)
|
||||
// `..` row mirrors the header Up button so the listing itself is
|
||||
// navigable without reaching for the header on mobile. Prepended after
|
||||
// sort so it always sits at the top regardless of folder names.
|
||||
var out []entry
|
||||
if urlPath != "/" {
|
||||
out = append(out, entry{
|
||||
Icon: iconUp,
|
||||
Name: "..",
|
||||
URL: parentURL(urlPath),
|
||||
})
|
||||
}
|
||||
out = append(out, folders...)
|
||||
out = append(out, files...)
|
||||
return out
|
||||
}
|
||||
|
||||
func readIcon(name string) template.HTML {
|
||||
@@ -192,21 +205,6 @@ func formatSize(b int64) string {
|
||||
}
|
||||
}
|
||||
|
||||
func buildCrumbs(urlPath string) []crumb {
|
||||
if urlPath == "/" {
|
||||
return nil
|
||||
}
|
||||
parts := strings.Split(strings.Trim(urlPath, "/"), "/")
|
||||
crumbs := make([]crumb, len(parts))
|
||||
for i, p := range parts {
|
||||
crumbs[i] = crumb{
|
||||
Name: p,
|
||||
URL: "/" + strings.Join(parts[:i+1], "/") + "/",
|
||||
}
|
||||
}
|
||||
return crumbs
|
||||
}
|
||||
|
||||
func pageTitle(urlPath string) string {
|
||||
if urlPath == "/" {
|
||||
return "Datascape"
|
||||
|
||||
Reference in New Issue
Block a user