浏览代码

View file

Min 8 年之前
父节点
当前提交
35b10f69fa
共有 3 个文件被更改,包括 11 次插入1 次删除
  1. 2 0
      main.go
  2. 8 1
      template.go
  3. 1 0
      utils.go

+ 2 - 0
main.go

@@ -113,6 +113,7 @@ func serveDirectory(w http.ResponseWriter, r *http.Request) {
 			Size: file.Size(),
 			Date: file.ModTime(),
 			Valid: true,
+			Directory: false,
 			}
 	}
 	tmpl.ExecuteTemplate(w, "index", &page)
@@ -181,6 +182,7 @@ func serveIndex(w http.ResponseWriter, r *http.Request) {
 		page.Items[i].Name = name
 		page.Items[i].URL = url.QueryEscape(name)
 		page.Items[i].Valid = true
+		page.Items[i].Directory = true
 		i++
 	}
 	tmpl.ExecuteTemplate(w, "index", &page)

+ 8 - 1
template.go

@@ -32,7 +32,14 @@ const index = `
         <tbody>
         {{range .Items}}{{ if .Valid}}
         <tr>
-            <td><a href="{{.URL}}?tarball=1" class="pure-menu-link">{{.Name}}</a></td>
+			<td>
+				{{ if .Directory }}
+				<a href="{{.URL}}" class="pure-menu-link"><b>{{.Name}}</b></a>
+				{{ else }}
+				<a href="{{.URL}}?tarball=1" class="pure-menu-link"><b>{{.Name}}</b></a>
+				<a href="{{.URL}}" class="pure-menu-link">(View)</a>
+				{{end}}
+			</td>
             <td>{{.FSize}}</td>
             <td>{{.FDate}}</td>
         </tr>

+ 1 - 0
utils.go

@@ -17,6 +17,7 @@ type Item struct {
 	Size int64
 	URL string
 	Date time.Time
+	Directory bool
 	Valid bool
 }