clear section list
This commit is contained in:
parent
f01d86a0d3
commit
48ed5014eb
3 changed files with 52 additions and 10 deletions
|
@ -37,7 +37,6 @@ gemtext. Executed from the hugo directory:
|
||||||
hugoext -ext gmi -pipe md2gmi
|
hugoext -ext gmi -pipe md2gmi
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
It abides the hugo section config in `[permalinks]` but only uses the content subdirectory to
|
It abides the hugo section config in `[permalinks]` but only uses the content subdirectory to
|
||||||
determine the section. An example section config in hugo looks like this:
|
determine the section. An example section config in hugo looks like this:
|
||||||
|
|
||||||
|
@ -69,11 +68,12 @@ files. Here an example for a Gemlog using [gmifs](https://github.com/n0x1m/gmifs
|
||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
serve:
|
serve:
|
||||||
hugoext -ext gmi -pipe md2gmi -serve="gmifs -autoindex"
|
hugoext -ext gmi -pipe md2gmi
|
||||||
|
gmifs -autoindex
|
||||||
```
|
```
|
||||||
|
|
||||||
hugoext pipes the input through the `md2gmi` extension and spawns `gmifs` to serve the local gemini
|
hugoext pipes the input through the `md2gmi` extension and writes the output file tree. We then
|
||||||
directory with auto indexing enabled.
|
spawn `gmifs` to serve it on `gemini://localhost` with auto indexing enabled.
|
||||||
|
|
||||||
### Production
|
### Production
|
||||||
|
|
||||||
|
|
8
main.go
8
main.go
|
@ -180,15 +180,11 @@ func main() {
|
||||||
section, ok := sections[seconOnRoot]
|
section, ok := sections[seconOnRoot]
|
||||||
if ok {
|
if ok {
|
||||||
sectionFile := filepath.Join(destination, "index."+ext)
|
sectionFile := filepath.Join(destination, "index."+ext)
|
||||||
|
// TODO: come up with sth better as one might have content there.
|
||||||
|
os.Remove(sectionFile)
|
||||||
section.Write(sectionFile)
|
section.Write(sectionFile)
|
||||||
fmt.Printf("written section listing for root to %s\n", section.File)
|
fmt.Printf("written section listing for root to %s\n", section.File)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
// in watch mode, compare timestamps of files before replacement, keep index?
|
|
||||||
// check/replace links
|
|
||||||
// write rss?
|
|
||||||
// write listings from template?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pipe(cmd string, input io.Reader) []byte {
|
func pipe(cmd string, input io.Reader) []byte {
|
||||||
|
|
46
section_list.go
Normal file
46
section_list.go
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Section struct {
|
||||||
|
List []SectionEntry
|
||||||
|
File string
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectionEntry struct {
|
||||||
|
Link string
|
||||||
|
Title string
|
||||||
|
Date time.Time
|
||||||
|
Summary string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (section *Section) Write(file string) error {
|
||||||
|
// sort section list
|
||||||
|
sort.Slice(section.List, func(i, j int) bool {
|
||||||
|
return section.List[i].Date.Before(section.List[j].Date)
|
||||||
|
})
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
for _, file := range section.List {
|
||||||
|
// TODO: this could be a template
|
||||||
|
entry := "\n"
|
||||||
|
entry += fmt.Sprintf("=> %s %s\n", file.Link, file.Title)
|
||||||
|
entry += fmt.Sprintf("%v - %s\n", file.Date.Format("2006-01-02"), file.Summary)
|
||||||
|
|
||||||
|
buf.Write([]byte(entry))
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.OpenFile(file, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = f.Write(buf.Bytes())
|
||||||
|
f.Close()
|
||||||
|
return err
|
||||||
|
}
|
Loading…
Reference in a new issue