templates.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2016 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package http
  17. import (
  18. "html/template"
  19. "path"
  20. "github.com/ethereum/go-ethereum/swarm/api"
  21. )
  22. type htmlListData struct {
  23. URI *api.URI
  24. List *api.ManifestList
  25. }
  26. var htmlListTemplate = template.Must(template.New("html-list").Funcs(template.FuncMap{"basename": path.Base}).Parse(`
  27. <!DOCTYPE html>
  28. <html>
  29. <head>
  30. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  31. <meta name="viewport" content="width=device-width, initial-scale=1">
  32. <title>Swarm index of {{ .URI }}</title>
  33. </head>
  34. <body>
  35. <h1>Swarm index of {{ .URI }}</h1>
  36. <hr>
  37. <table>
  38. <thead>
  39. <tr>
  40. <th>Path</th>
  41. <th>Type</th>
  42. <th>Size</th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. {{ range .List.CommonPrefixes }}
  47. <tr>
  48. <td><a href="{{ basename . }}/?list=true">{{ basename . }}/</a></td>
  49. <td>DIR</td>
  50. <td>-</td>
  51. </tr>
  52. {{ end }}
  53. {{ range .List.Entries }}
  54. <tr>
  55. <td><a href="{{ basename .Path }}">{{ basename .Path }}</a></td>
  56. <td>{{ .ContentType }}</td>
  57. <td>{{ .Size }}</td>
  58. </tr>
  59. {{ end }}
  60. </table>
  61. <hr>
  62. </body>
  63. `[1:]))