diff --git a/gateway/core/corehttp/gateway_indexPage.go b/gateway/core/corehttp/gateway_indexPage.go
index 79ad935b1..f6fa92f9e 100644
--- a/gateway/core/corehttp/gateway_indexPage.go
+++ b/gateway/core/corehttp/gateway_indexPage.go
@@ -1,8 +1,10 @@
package corehttp
import (
+ "github.com/ipfs/go-ipfs/assets"
"html/template"
"path"
+ "strings"
)
// structs for directory listing
@@ -18,143 +20,37 @@ type directoryItem struct {
Path string
}
-// Directory listing template
-var listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{"iconFromExt": iconFromExt}).Parse(`
-
-
-
-
-
-
-
-
-
- {{ .Path }}
-
-
-
-
-
-
-
- Index of {{ .Path }}
-
-
-
-
-
- |
-
- ..
- |
- |
-
- {{ range .Listing }}
-
-
-
- |
-
- {{ .Name }}
- |
- {{ .Size }} bytes |
-
- {{ end }}
-
-
-
-
-
-`))
+var listingTemplate *template.Template
-// helper to guess the type/icon for it by the extension name
-func iconFromExt(name string) string {
- ext := path.Ext(name)
- _, ok := knownIcons[ext]
- if !ok {
- // default blank icon
- return "ipfs-_blank"
+func init() {
+ assetPath := "../vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/"
+ knownIconsBytes, err := assets.Asset(assetPath + "knownIcons.txt")
+ if err != nil {
+ panic(err)
+ }
+ knownIcons := make(map[string]struct{})
+ for _, ext := range strings.Split(strings.TrimSuffix(string(knownIconsBytes), "\n"), "\n") {
+ knownIcons[ext] = struct{}{}
+ }
+
+ // helper to guess the type/icon for it by the extension name
+ iconFromExt := func(name string) string {
+ ext := path.Ext(name)
+ _, ok := knownIcons[ext]
+ if !ok {
+ // default blank icon
+ return "ipfs-_blank"
+ }
+ return "ipfs-" + ext[1:] // slice of the first dot
+ }
+
+ // Directory listing template
+ dirIndexBytes, err := assets.Asset(assetPath + "dir-index.html")
+ if err != nil {
+ panic(err)
}
- return "ipfs-" + ext[1:] // slice of the first dot
-}
-var knownIcons = map[string]bool{
- ".aac": true,
- ".aiff": true,
- ".ai": true,
- ".avi": true,
- ".bmp": true,
- ".c": true,
- ".cpp": true,
- ".css": true,
- ".dat": true,
- ".dmg": true,
- ".doc": true,
- ".dotx": true,
- ".dwg": true,
- ".dxf": true,
- ".eps": true,
- ".exe": true,
- ".flv": true,
- ".gif": true,
- ".h": true,
- ".hpp": true,
- ".html": true,
- ".ics": true,
- ".iso": true,
- ".java": true,
- ".jpg": true,
- ".js": true,
- ".key": true,
- ".less": true,
- ".mid": true,
- ".mp3": true,
- ".mp4": true,
- ".mpg": true,
- ".odf": true,
- ".ods": true,
- ".odt": true,
- ".otp": true,
- ".ots": true,
- ".ott": true,
- ".pdf": true,
- ".php": true,
- ".png": true,
- ".ppt": true,
- ".psd": true,
- ".py": true,
- ".qt": true,
- ".rar": true,
- ".rb": true,
- ".rtf": true,
- ".sass": true,
- ".scss": true,
- ".sql": true,
- ".tga": true,
- ".tgz": true,
- ".tiff": true,
- ".txt": true,
- ".wav": true,
- ".xls": true,
- ".xlsx": true,
- ".xml": true,
- ".yml": true,
- ".zip": true,
+ listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{
+ "iconFromExt": iconFromExt,
+ }).Parse(string(dirIndexBytes)))
}