-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (59 loc) · 1.84 KB
/
main.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"errors"
"flag"
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/gookit/config/v2"
"github.com/gookit/config/v2/yamlv3"
"github.com/joshmenden/n2h/internal/draft"
"github.com/joshmenden/n2h/internal/log"
"github.com/joshmenden/n2h/internal/markdown"
"github.com/joshmenden/n2h/internal/notionfind"
)
var PWD string
func main() {
if PWD == "" { // not installed or built, running `go run`, assume they are in the root dir
d, err := os.Getwd()
if err != nil {
log.Error(err)
}
PWD = d
}
pageTitle := flag.String("title", "", "The complete title of the Notion article you're ready to publish")
statusProperty := flag.String("status-property", "Status", "The name of the `status` property to look for a specific article in")
status := flag.String("status", "", "The value of the status in which the desired article is found")
flag.Parse()
if *pageTitle == "" || *status == "" {
log.Error(errors.New("missing required flags `status` or `pageTitle`"))
}
config.WithOptions(config.ParseEnv)
config.AddDriver(yamlv3.Driver)
err := config.LoadFiles(PWD + "/secrets.yml")
if err != nil {
log.Error(err)
}
log.Status("fetching content from Notion", "🏇")
page, blocks, err := notionfind.Content(pageTitle, statusProperty, status)
if err != nil {
log.Error(err)
}
log.Status("building markdown from blocks", "🔨")
content, err := markdown.Build(page, blocks)
if err != nil {
log.Error(err)
}
log.Status("creating hugo blog template with markdown", "🌍")
ok, err := draft.GenerateAndSaveDraftFile(&draft.Info{
Title: markdown.TitleFromPage(page),
Filename: fmt.Sprintf("%s.md", markdown.ToSnakeCase(markdown.TitleFromPage(page))),
Description: nil,
Draft: aws.Bool(true),
Content: *content,
}, PWD)
if !ok {
log.Error(err)
}
log.Status("draft created", "✅")
}