@@ -17,6 +17,10 @@ type pathEntry struct {
1717 Path string
1818}
1919
20+ type subItemSort struct {
21+ Name []byte
22+ }
23+
2024type subItemHtml struct {
2125 IsDir bool
2226 Name template.HTML
@@ -25,8 +29,10 @@ type subItemHtml struct {
2529}
2630
2731type subItem struct {
32+ sort subItemSort
33+
2834 Info os.FileInfo
29- Html subItemHtml
35+ Html * subItemHtml
3036}
3137
3238type responseData struct {
@@ -200,25 +206,6 @@ func getSubItemPrefix(requestPath string, tailSlash bool) (subItemPrefix string)
200206 return
201207}
202208
203- func sortSubInfos (subInfos []os.FileInfo ) {
204- sort .Slice (
205- subInfos ,
206- func (prevIndex , nextIndex int ) bool {
207- prevItem := subInfos [prevIndex ]
208- nextItem := subInfos [nextIndex ]
209-
210- prevIsDir := prevItem .IsDir ()
211- nextIsDir := nextItem .IsDir ()
212-
213- if prevIsDir != nextIsDir {
214- return prevIsDir
215- }
216-
217- return util .CompareNumInStr ([]byte (prevItem .Name ()), []byte (nextItem .Name ()))
218- },
219- )
220- }
221-
222209func getItemName (info os.FileInfo , r * http.Request ) (itemName string ) {
223210 if info != nil {
224211 itemName = info .Name ()
@@ -235,19 +222,47 @@ func getSubItems(subInfos []os.FileInfo) []*subItem {
235222 for i := 0 ; i < len (subInfos ); i ++ {
236223 info := subInfos [i ]
237224 subItems [i ] = & subItem {
238- Info : info ,
239- Html : subItemHtml {
240- IsDir : info .IsDir (),
241- Name : tplutil .FormatFilename (info .Name ()),
242- Size : tplutil .FormatSize (info .Size ()),
243- ModTime : tplutil .FormatTime (info .ModTime ()),
225+ sort : subItemSort {
226+ Name : []byte (info .Name ()),
244227 },
228+ Info : info ,
245229 }
246230 }
247231
248232 return subItems
249233}
250234
235+ func updateSubsItemHtml (subItems []* subItem ) {
236+ for _ , item := range subItems {
237+ info := item .Info
238+ item .Html = & subItemHtml {
239+ IsDir : info .IsDir (),
240+ Name : tplutil .FormatFilename (info .Name ()),
241+ Size : tplutil .FormatSize (info .Size ()),
242+ ModTime : tplutil .FormatTime (info .ModTime ()),
243+ }
244+ }
245+ }
246+
247+ func sortSubItems (subItems []* subItem ) {
248+ sort .Slice (
249+ subItems ,
250+ func (prevIndex , nextIndex int ) bool {
251+ prevItem := subItems [prevIndex ]
252+ nextItem := subItems [nextIndex ]
253+
254+ prevIsDir := prevItem .Info .IsDir ()
255+ nextIsDir := nextItem .Info .IsDir ()
256+
257+ if prevIsDir != nextIsDir {
258+ return prevIsDir
259+ }
260+
261+ return util .CompareNumInStr (prevItem .sort .Name , nextItem .sort .Name )
262+ },
263+ )
264+ }
265+
251266func (h * handler ) getResponseData (r * http.Request ) (data * responseData ) {
252267 requestUri := r .URL .Path
253268 tailSlash := requestUri [len (requestUri )- 1 ] == '/'
@@ -291,9 +306,9 @@ func (h *handler) getResponseData(r *http.Request) (data *responseData) {
291306 internalError = internalError || len (_mergeErrs ) > 0
292307
293308 subInfos = h .FilterItems (subInfos )
294- sortSubInfos (subInfos )
295309
296310 subItems := getSubItems (subInfos )
311+ sortSubItems (subItems )
297312
298313 subItemPrefix := getSubItemPrefix (reqPath , tailSlash )
299314
0 commit comments