mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
Sort pages by date
This commit is contained in:
parent
98dc3d769e
commit
772b801eea
21
kiln.go
21
kiln.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
@ -40,7 +41,7 @@ func LoadSite(srcDir string) (*Site, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write writes the contents of the Index to the provided destination directory.
|
// Write writes the contents of the Index to the provided destination directory.
|
||||||
func (s *Site) Write(dstDir string) error {
|
func (s *Site) Write(dstDir string, format OutputFormat) error {
|
||||||
// Empty the destination directory
|
// Empty the destination directory
|
||||||
if err := os.RemoveAll(dstDir); err != nil {
|
if err := os.RemoveAll(dstDir); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -73,7 +74,7 @@ func (s *Site) Write(dstDir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the directory
|
// Write the directory
|
||||||
return s.Directory.Write(dstDir, OutputGemini)
|
return s.Directory.Write(dstDir, format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manipulate processes and manipulates the site's content.
|
// Manipulate processes and manipulates the site's content.
|
||||||
|
@ -114,6 +115,11 @@ func (s *Site) Manipulate(dir *Directory) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort sorts the site's pages by date.
|
||||||
|
func (s *Site) Sort() {
|
||||||
|
s.Directory.Sort()
|
||||||
|
}
|
||||||
|
|
||||||
// Page represents a page.
|
// Page represents a page.
|
||||||
type Page struct {
|
type Page struct {
|
||||||
// The path to this page.
|
// The path to this page.
|
||||||
|
@ -296,6 +302,17 @@ func (d *Directory) Write(dstDir string, format OutputFormat) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort sorts the directory's pages by date.
|
||||||
|
func (d *Directory) Sort() {
|
||||||
|
sort.Slice(d.Pages, func(i, j int) bool {
|
||||||
|
return d.Pages[i].Date.After(d.Pages[j].Date)
|
||||||
|
})
|
||||||
|
// Sort subdirectories
|
||||||
|
for _, d := range d.Directories {
|
||||||
|
d.Sort()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// OutputFormat represents an output format.
|
// OutputFormat represents an output format.
|
||||||
type OutputFormat func(*Page) (path string, content []byte)
|
type OutputFormat func(*Page) (path string, content []byte)
|
||||||
|
|
||||||
|
|
5
main.go
5
main.go
|
@ -35,14 +35,15 @@ func build() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
site.Sort()
|
||||||
if err := site.Manipulate(site.Directory); err != nil {
|
if err := site.Manipulate(site.Directory); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := site.Write("dst"); err != nil {
|
if err := site.Write("dst", OutputGemini); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if toHtml {
|
if toHtml {
|
||||||
if err := site.Directory.Write("dst.html", OutputHTML); err != nil {
|
if err := site.Write("dst.html", OutputHTML); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue