forked from kjk/notionapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_md.go
45 lines (39 loc) · 1007 Bytes
/
to_md.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
package main
import (
"fmt"
"path/filepath"
"github.com/kjk/u"
"github.com/ninja-1/notionapi"
"github.com/ninja-1/notionapi/tomarkdown"
)
func mdPath(pageID string, n int) string {
pageID = notionapi.ToNoDashID(pageID)
name := fmt.Sprintf("%s.%d.page.html", pageID, n)
return filepath.Join(cacheDir, name)
}
func toMd(pageID string) *notionapi.Page {
client := makeNotionClient()
page, err := downloadPage(client, pageID)
if err != nil {
logf("toHTML: downloadPage() failed with '%s'\n", err)
return nil
}
if page == nil {
logf("toHTML: page is nil\n")
return nil
}
notionapi.PanicOnFailures = true
c := tomarkdown.NewConverter(page)
md := c.ToMarkdown()
path := htmlPath(pageID, 2)
u.WriteFileMust(path, md)
logf("%s : MarkDown version of the page\n", path)
if !flgNoOpen {
path, err := filepath.Abs(path)
must(err)
uri := "file://" + path
logf("Opening browser with %s\n", uri)
u.OpenBrowser(uri)
}
return page
}