Create a new zettel with a given title
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
59c4d132b2
commit
b2f7f7af7f
3 changed files with 78 additions and 0 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
@ -12,6 +13,32 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func CreateZet(title string) {
|
||||
zid := newZid()
|
||||
|
||||
fmt.Println(title, zid)
|
||||
|
||||
path := path.Join(GetZetDir(), strconv.Itoa(zid))
|
||||
|
||||
os.Mkdir(path, 0750)
|
||||
|
||||
filePath := fmt.Sprintf("%s/index.adoc", path)
|
||||
|
||||
file, err := os.Create(filePath)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
_, err = fmt.Fprintf(file, "= %s", title)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func EditZet(id int) {
|
||||
zetPath := path.Join(GetZetDir(), strconv.Itoa(id), "index.adoc")
|
||||
|
||||
|
@ -139,6 +166,24 @@ func getTitleFromFile(filePath string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func newZid() int {
|
||||
cmd := exec.Command("ls", GetZetDir())
|
||||
output, _ := cmd.CombinedOutput()
|
||||
|
||||
zets := strings.Split(string(output), "\n")
|
||||
|
||||
var zetCount int
|
||||
|
||||
for _, zet := range zets {
|
||||
num, err := strconv.Atoi(zet)
|
||||
if err == nil && num > zetCount {
|
||||
zetCount = num
|
||||
}
|
||||
}
|
||||
|
||||
return zetCount + 1
|
||||
}
|
||||
|
||||
func onSave(id int) {
|
||||
title := getTitle(id)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue