Skip to content

Commit

Permalink
Fixed some short list stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimau committed Jul 25, 2021
1 parent f93c4e8 commit 5eea14b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion build_gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func (gl GalleryList) Less(i, j int) bool {
return a < b
}

type GalleryListByDate []*GalleryPost

func (gl GalleryListByDate) Len() int { return len(gl) }
func (gl GalleryListByDate) Swap(i, j int) { gl[i], gl[j] = gl[j], gl[i] }
func (gl GalleryListByDate) Less(i, j int) bool { return gl[i].Date.After(gl[j].Date) }

// Support for .png .gif .jpg .mp4 .txt .html
func LoadGalleryFile(path string, info os.FileInfo, err error) error {
if err != nil {
Expand Down Expand Up @@ -140,7 +146,12 @@ func LoadGalleryFile(path string, info os.FileInfo, err error) error {
return fmt.Sprintf(`src="%s"`, dFile)
}))

newPost.Brief = regHeader.FindString(string(newPost.Body))
headers := regHeader.FindStringSubmatch(string(newPost.Body))
if len(headers) > 1 {
newPost.Brief = headers[2]
} else {
newPost.Brief = string(string(newPost.Body))
}

} else if ext == ".html" {
body, err := os.ReadFile(path)
Expand All @@ -156,6 +167,13 @@ func LoadGalleryFile(path string, info os.FileInfo, err error) error {

return fmt.Sprintf(`src="%s"`, dFile)
}))

headers := regHeader.FindStringSubmatch(string(newPost.Body))
if len(headers) > 1 {
newPost.Brief = headers[1]
} else {
newPost.Brief = string(string(newPost.Body))
}
} else if ext == ".json" {
return nil
} else {
Expand Down Expand Up @@ -274,4 +292,10 @@ func GenerateGallery() {
outFile.Close()
}

genData.ShortGallery = nil
genData.ShortGallery = append(genData.ShortGallery, genData.Gallery...)
sort.Sort(genData.ShortGallery)
if len(genData.ShortGallery) > 8 {
genData.ShortGallery = genData.ShortGallery[:8]
}
}

0 comments on commit 5eea14b

Please sign in to comment.