mirror of
https://github.com/yv1ing/MollyBlog.git
synced 2025-09-16 14:53:45 +08:00
new: Complete modules related to home page, archive page and article page
This commit is contained in:
6
internal/model/mCategory.go
Normal file
6
internal/model/mCategory.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type MCategory struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Hash string `yaml:"hash" json:"hash"`
|
||||
}
|
||||
7
internal/model/mFileInfo.go
Normal file
7
internal/model/mFileInfo.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
// MFileInfo basic file info
|
||||
type MFileInfo struct {
|
||||
Name string
|
||||
Path string
|
||||
}
|
||||
49
internal/model/mPost.go
Normal file
49
internal/model/mPost.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
// MPost post metadata
|
||||
type MPost struct {
|
||||
Title string `yaml:"title" json:"title"`
|
||||
Cover string `yaml:"cover" json:"cover"`
|
||||
Date string `yaml:"date" json:"date"`
|
||||
|
||||
Tags []string `yaml:"tags" json:"tags"`
|
||||
TagHashes []MTag `yaml:"tag_hashes" json:"tag_hashes"`
|
||||
|
||||
Categories []string `yaml:"categories" json:"categories"`
|
||||
CategoryHashes []MCategory `yaml:"category_hashes" json:"category_hashes"`
|
||||
|
||||
HtmlHash string `yaml:"htmlHash" json:"html_hash"`
|
||||
HtmlPath string `yaml:"htmlPath" json:"html_path"`
|
||||
}
|
||||
|
||||
type MPostSlice []*MPost
|
||||
|
||||
func (a MPostSlice) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
|
||||
func (a MPostSlice) Swap(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
||||
|
||||
func (a MPostSlice) Less(i, j int) bool {
|
||||
timeFormat := "2006-01-02 15:04:05"
|
||||
t1, err1 := time.Parse(timeFormat, a[i].Date)
|
||||
t2, err2 := time.Parse(timeFormat, a[j].Date)
|
||||
|
||||
if err1 != nil || err2 != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return t1.After(t2)
|
||||
}
|
||||
|
||||
func SortPostsByDate(Posts []*MPost) []*MPost {
|
||||
sort.Sort(MPostSlice(Posts))
|
||||
return Posts
|
||||
}
|
||||
6
internal/model/mTag.go
Normal file
6
internal/model/mTag.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type MTag struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Hash string `yaml:"hash" json:"hash"`
|
||||
}
|
||||
Reference in New Issue
Block a user