-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (58 loc) · 1.72 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
74
75
76
77
78
79
package main
import (
"time"
"github.com/alecthomas/kong"
"github.com/joho/godotenv"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"export-logseq/hugo"
"export-logseq/logseq"
)
type EnvFlag string
// BeforeResolve loads .env file before resolving the command line arguments.
func (c EnvFlag) BeforeReset(ctx *kong.Context, trace *kong.Path) error {
path := string(ctx.FlagValue(trace.Flag).(EnvFlag)) //nolint
path = kong.ExpandPath(path)
log.Infof("Loading .env file from %s", path)
if err := godotenv.Load(path); err != nil {
return err
}
return nil
}
type SelectedPages string
const (
AllPages SelectedPages = "all"
PublicPages SelectedPages = "public"
)
type ExportCmd struct {
GraphDir string `arg:"" env:"GRAPH_DIR" help:"Path to the Logseq graph directory."`
SiteDir string `arg:"" env:"SITE_DIR" help:"Path to the site directory."`
SelectedPages SelectedPages `default:"public" enum:"all,public" help:"Select pages to export."`
}
func (cmd *ExportCmd) Run() error {
graph, err := logseq.LoadGraph(cmd.GraphDir)
if err != nil {
return errors.Wrap(err, "loading graph")
}
requirePublic := cmd.SelectedPages == PublicPages
if err := hugo.ExportGraph(graph, cmd.SiteDir, requirePublic); err != nil {
return errors.Wrap(err, "exporting graph")
}
return nil
}
type CLI struct {
EnvFile EnvFlag
Export ExportCmd `cmd:"" help:"Export a Logseq graph to SSG content folder."`
}
func main() {
log.SetLevel(log.InfoLevel)
log.Info("Initializing...")
var cli CLI
start := time.Now()
ctx := kong.Parse(&cli)
err := ctx.Run()
ctx.FatalIfErrorf(err)
elapsed := time.Since(start)
log.Info("All done!")
log.Infof("Elapsed time: %s", elapsed)
}