58 lines
996 B
Go
58 lines
996 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
zord_tree "g.arns.lt/zordsdavini/zord-tree"
|
||
|
"sort"
|
||
|
)
|
||
|
|
||
|
type FSummery struct {
|
||
|
Name string
|
||
|
Category []string
|
||
|
Description string
|
||
|
Id string
|
||
|
Lang string
|
||
|
Created string
|
||
|
Copyright string
|
||
|
Tags []string
|
||
|
}
|
||
|
|
||
|
type TSummery struct {
|
||
|
Files []FSummery
|
||
|
Tags map[string]int
|
||
|
Categories map[string]int
|
||
|
}
|
||
|
|
||
|
type FileContent struct {
|
||
|
File zord_tree.File
|
||
|
Content string
|
||
|
}
|
||
|
|
||
|
func GetLastFiles(files []FSummery) []FSummery {
|
||
|
sortingFiles := make(map[string]FSummery)
|
||
|
for _, f := range files {
|
||
|
sortingFiles[f.Created+f.Id] = f
|
||
|
}
|
||
|
|
||
|
keys := make([]string, 0, len(sortingFiles))
|
||
|
for k := range sortingFiles {
|
||
|
keys = append(keys, k)
|
||
|
}
|
||
|
sort.Strings(keys)
|
||
|
sort.Reverse(sort.StringSlice(keys))
|
||
|
|
||
|
length := 10
|
||
|
if len(keys) < 10 {
|
||
|
length = len(keys)
|
||
|
}
|
||
|
lastFiles := make([]FSummery, 0, length)
|
||
|
for i, k := range keys {
|
||
|
if i == length {
|
||
|
break
|
||
|
}
|
||
|
|
||
|
lastFiles = append(lastFiles, sortingFiles[k])
|
||
|
}
|
||
|
|
||
|
return lastFiles
|
||
|
}
|