forked from ikeikeikeike/go-sitemap-generator
/
options.go
150 lines (128 loc) · 3.79 KB
/
options.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package stm
// NewOptions returns the created the Options's pointer
func NewOptions() *Options {
// Default values
return &Options{
defaultHost: "http://www.example.com",
sitemapsHost: "", // http://s3.amazonaws.com/sitemap-generator/,
publicPath: "public/",
sitemapsPath: "sitemaps/",
filename: "sitemap",
verbose: true,
compress: true,
pretty: false,
adp: NewFileAdapter(),
}
}
// Options exists for the Sitemap struct.
type Options struct {
defaultHost string
sitemapsHost string
publicPath string
sitemapsPath string
filename string
verbose bool
compress bool
pretty bool
adp Adapter
nmr *Namer
loc *Location
image bool
video bool
geo bool
news bool
mobile bool
pagemap bool
}
// SetDefaultHost sets that arg from Sitemap.Finalize method
func (opts *Options) SetDefaultHost(host string) {
opts.defaultHost = host
}
// SetSitemapsHost sets that arg from Sitemap.SetSitemapsHost method
func (opts *Options) SetSitemapsHost(host string) {
opts.sitemapsHost = host
}
// SetSitemapsPath sets that arg from Sitemap.SetSitemapsPath method.
func (opts *Options) SetSitemapsPath(path string) {
opts.sitemapsPath = path
}
// SetPublicPath sets that arg from Sitemap.SetPublicPath method
func (opts *Options) SetPublicPath(path string) {
opts.publicPath = path
}
// SetFilename sets that arg from Sitemap.SetFilename method
func (opts *Options) SetFilename(filename string) {
opts.filename = filename
}
// SetVerbose sets that arg from Sitemap.SetVerbose method
func (opts *Options) SetVerbose(verbose bool) {
opts.verbose = verbose
}
// SetCompress sets that arg from Sitemap.SetCompress method
func (opts *Options) SetCompress(compress bool) {
opts.compress = compress
}
// SetPretty option sets pretty option to Options struct which allows pretty formatting to output files.
func (opts *Options) SetPretty(pretty bool) {
opts.pretty = pretty
}
// SetAdapter sets that arg from Sitemap.SetAdapter method
func (opts *Options) SetAdapter(adp Adapter) {
opts.adp = adp
}
// SetImage inject image header in xml additional headers
func (opts *Options) SetImage(image bool) {
opts.image = image
}
// SetVideo inject video header in xml additional headers
func (opts *Options) SetVideo(video bool) {
opts.video = video
}
// SetGeo inject video header in xml additional headers
func (opts *Options) SetGeo(geo bool) {
opts.geo = geo
}
// SetNews inject news header in xml additional headers
func (opts *Options) SetNews(news bool) {
opts.news = news
}
// SetMobile inject mobile header in xml additional headers
func (opts *Options) SetMobile(mobile bool) {
opts.mobile = mobile
}
// SetPageMap inject pagemap header in xml additional headers
func (opts *Options) SetPageMap(pagemap bool) {
opts.pagemap = pagemap
}
// SitemapsHost sets that arg from Sitemap.SitemapsHost method
func (opts *Options) SitemapsHost() string {
if opts.sitemapsHost != "" {
return opts.sitemapsHost
}
return opts.defaultHost
}
// Location returns the Location's pointer with
// set option to arguments for Builderfile struct.
func (opts *Options) Location() *Location {
return NewLocation(opts)
}
// IndexLocation returns the Location's pointer with
// set option to arguments for BuilderIndexfile struct.
func (opts *Options) IndexLocation() *Location {
o := opts.Clone()
o.nmr = NewNamer(&NOpts{base: opts.filename})
return NewLocation(o)
}
// Namer returns Namer's pointer cache. If didn't create that yet,
// It also returns created Namer's pointer.
func (opts *Options) Namer() *Namer {
if opts.nmr == nil {
opts.nmr = NewNamer(&NOpts{base: opts.filename, zero: 1, start: 2})
}
return opts.nmr
}
// Clone method returns it copied myself.
func (opts *Options) Clone() *Options {
o := *opts
return &o
}