-
Notifications
You must be signed in to change notification settings - Fork 1
/
system_site.go
109 lines (88 loc) · 2.7 KB
/
system_site.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package config
import (
"time"
"github.com/ambientkit/ambient"
"github.com/ambientkit/ambient/pkg/amberror"
)
// SetTitle sets the title.
func (p *PluginSystem) SetTitle(title string) error {
p.storage.site.Title = title
return p.storage.Save()
}
// Title returns the title.
func (p *PluginSystem) Title() string {
return p.storage.site.Title
}
// SetScheme sets the site scheme.
func (p *PluginSystem) SetScheme(scheme string) error {
p.storage.site.Scheme = scheme
return p.storage.Save()
}
// Scheme returns the site scheme.
func (p *PluginSystem) Scheme() string {
return p.storage.site.Scheme
}
// SetURL sets the site URL.
func (p *PluginSystem) SetURL(URL string) error {
p.storage.site.URL = URL
return p.storage.Save()
}
// URL returns the URL without the scheme at the beginning.
func (p *PluginSystem) URL() string {
return p.storage.site.URL
}
// FullURL returns the URL with the scheme at the beginning.
func (p *PluginSystem) FullURL() string {
return p.storage.site.SiteURL()
}
// Updated returns the home last updated timestamp.
func (p *PluginSystem) Updated() time.Time {
return p.storage.site.Updated
}
// Tags returns the list of tags.
func (p *PluginSystem) Tags(onlyPublished bool) ambient.TagList {
return p.storage.site.Tags(onlyPublished)
}
// SetContent sets the home page content.
func (p *PluginSystem) SetContent(content string) error {
p.storage.site.Content = content
return p.storage.Save()
}
// Content returns the site home page content.
func (p *PluginSystem) Content() string {
return p.storage.site.Content
}
// SavePost saves a post.
func (p *PluginSystem) SavePost(ID string, post ambient.Post) error {
p.storage.site.Posts[ID] = post
return p.storage.Save()
}
// PostsAndPages returns the list of posts and pages.
func (p *PluginSystem) PostsAndPages(onlyPublished bool) ambient.PostWithIDList {
return p.storage.site.PostsAndPages(onlyPublished)
}
// PublishedPosts returns the list of published posts.
func (p *PluginSystem) PublishedPosts() []ambient.Post {
return p.storage.site.PublishedPosts()
}
// PublishedPages returns the list of published pages.
func (p *PluginSystem) PublishedPages() []ambient.Post {
return p.storage.site.PublishedPages()
}
// PostBySlug returns the post by slug.
func (p *PluginSystem) PostBySlug(slug string) ambient.PostWithID {
return p.storage.site.PostBySlug(slug)
}
// PostByID returns the post by ID.
func (p *PluginSystem) PostByID(ID string) (ambient.Post, error) {
post, ok := p.storage.site.Posts[ID]
if !ok {
return ambient.Post{}, amberror.ErrNotFound
}
return post, nil
}
// DeletePostByID deletes a post.
func (p *PluginSystem) DeletePostByID(ID string) error {
delete(p.storage.site.Posts, ID)
return p.storage.Save()
}