-
Notifications
You must be signed in to change notification settings - Fork 23
/
markdown_writer.go
45 lines (40 loc) · 936 Bytes
/
markdown_writer.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 (
"log"
"os"
"path/filepath"
)
type MarkdownWriter struct{}
func (w MarkdownWriter) write(body string) {
markdown_file_name := mdPrefix + currentDate + mdSuffix + ".md"
f, err := os.OpenFile(filepath.Join(markdownDirPath, markdown_file_name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
if _, err := f.Write([]byte(body)); err != nil {
log.Fatal(err)
}
if err := f.Close(); err != nil {
log.Fatal(err)
}
}
func (w MarkdownWriter) writeLink(title string, url string, newline bool, readingTime string) string {
var content string
content = "[" + title + "](" + url + ")"
if readingTime != "" {
content += " (" + readingTime + ")"
}
if newline {
content += "\n"
}
return content
}
func (w MarkdownWriter) writeSummary(content string, newline bool) string {
if content == "" {
return content
}
if newline {
content += " \n\n"
}
return content
}