-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
87 lines (69 loc) · 2.12 KB
/
types.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
80
81
82
83
84
85
86
87
package blog
import (
"html/template"
"sort"
"github.com/frankmeza/blog-go-htmx/pkg/utils"
)
const (
DOT_MD string = ".md"
ERROR_IN_FUNC string = "error in func "
MARKDOWN_PAGES_PATH string = "pkg/markdown/pages/"
MARKDOWN_POSTS_PATH string = "pkg/markdown/posts/"
TEMPLATE_HOME string = "home"
TEMPLATE_MARKDOWN_PAGE string = "markdownPage"
)
type PostMetaData struct {
IsDraft bool `yaml:"is_draft" toml:"is_draft" json:"is_draft"`
Key string `yaml:"key" toml:"key" json:"key"`
Summary string `yaml:"summary" toml:"summary" json:"summary"`
Tags []string `yaml:"tags" toml:"tags" json:"tags"`
Title string `yaml:"title" toml:"title" json:"title"`
Type string `yaml:"type" toml:"type" json:"type"`
CreatedAt string `yaml:"created_at" toml:"created_at" json:"created_at"`
UpdatedAt string `yaml:"updated_at" toml:"updated_at" json:"updated_at"`
}
type GoTemplateSet struct {
templates *template.Template
}
type HtmlTemplateData struct {
Content template.HTML
}
type MarkdownDocument struct {
PostMetaData `yaml:"post_metadata" toml:"post_metadata" json:"post_metadata"`
Content []byte `yaml:"-" toml:"-" json:"-"`
ContentString string `yaml:"content" toml:"content" json:"content"`
}
type AppState struct {
Posts []MarkdownDocument
Pages []MarkdownDocument
Tags []string
}
func (a AppState) bootstrap() error {
pages, err := createDocuments(utils.UseRelativePath(MARKDOWN_PAGES_PATH))
if err != nil {
return utils.ReturnError("bootstrap:44 ", err)
}
appState.Pages = pages
posts, err := createDocuments(utils.UseRelativePath(MARKDOWN_POSTS_PATH))
if err != nil {
return utils.ReturnError("bootstrap:52 ", err)
}
appState.Posts = posts
allContent := append(pages, posts...)
var tags []string
sort.Strings(appState.Tags)
for _, doc := range allContent {
for _, tag := range doc.Tags {
if !utils.IsStringInSlice(tag, appState.Tags) {
tags = append(tags, tag)
}
}
}
appState.Tags = tags
return nil
}
func BackdoorBootstrap() *AppState {
backdoorAppState := appState
backdoorAppState.bootstrap()
return &backdoorAppState
}