~porcellis/t

ref: structure t/commands/create.go -rw-r--r-- 920 bytes
76f0d055 — Pedro Lucas Porcellis Generate a simple and nice doc 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package commands

import (
	"fmt"
	"git.sr.ht/~porcellis/t/config"
	"git.sr.ht/~porcellis/t/models"
	"os"
	"path"
	"time"
)

func CreateWithName(config config.TConfig, title string) (models.Note, error) {
	var (
		err  error
		note models.Note
	)

	file, err := os.Create(path.Join(config.BasePath, fmt.Sprintf("%s.md", title)))

	stat, _ := file.Stat()

	note = models.Note{Name: stat.Name(), Path: path.Join(config.BasePath, stat.Name()), ModTime: stat.ModTime()}

	return note, err

}

func Create(config config.TConfig) (models.Note, error) {
	var (
		err  error
		note models.Note
	)

	currentTime := time.Now()
	noteName := currentTime.Format("2006-01-02T15:04:05Z07:00")

	file, err := os.Create(path.Join(config.BasePath, fmt.Sprintf("%s.md", noteName)))

	stat, _ := file.Stat()
	note = models.Note{Name: stat.Name(), Path: path.Join(config.BasePath, stat.Name()), ModTime: stat.ModTime()}

	return note, err
}