/
aux_update.go
176 lines (136 loc) · 4.14 KB
/
aux_update.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"os"
"text/template"
"strconv"
"strings"
_ "github.com/mattn/go-sqlite3"
)
//structures used in templates
type Catalog struct {
Name string
Desc string
Posts []*Post
Subjects []string
Header []string
HeaderDescs []string
SThemes []string
}
type Hp struct {
BoardN string
Id int
Content string
ContentFull string
Parent string
Password string
}
type Ht struct {
BoardN string
Id int
Parent string
Imgprev string
Password string
}
type Home struct {
Title string
Latest []*Hp
Thumbs []*Ht
Header []string
HeaderDescs []string
News string
FAQ string
Rules string
Board_info string
SThemes []string
}
//catalog template function for making new rows
var catfuncmap = template.FuncMap{
"startrow": func(rowsize, index int) bool {
if index % rowsize == 0 {
return true
}
return false
},
"audiocheck": func(filemime string) bool {
if strings.HasPrefix(filemime, "audio") {return true}
return false
},
}
func get_cat_posts(board string) ([]*Post, []string) {
stmts := Checkout()
defer Checkin(stmts)
thread_collstmt := stmts["thread_coll"]
thread_headstmt := stmts["thread_head"]
var cat_body []*Post
var subjects []string
parent_rows, err := thread_collstmt.Query(board)
Err_check(err)
defer parent_rows.Close()
for parent_rows.Next() {
var cparent Post
var filler int
err = parent_rows.Scan(&cparent.Id, &filler)
Err_check(err)
err = thread_headstmt.QueryRow(cparent.Id, board).Scan(&cparent.Content, &cparent.Time, &cparent.Parent, &cparent.File,
&cparent.Filename, &cparent.Fileinfo, &cparent.Filemime, &cparent.Imgprev, &cparent.Option, &cparent.Pinned, &cparent.Locked, &cparent.Anchored)
Query_err_check(err)
cat_body = append(cat_body, &cparent)
subjects = append(subjects, Get_subject(strconv.Itoa(cparent.Id), board))
}
return cat_body, subjects
}
func get_home() ([]*Hp, []*Ht) {
stmts := Checkout()
defer Checkin(stmts)
hp_collstmt := stmts["hp_coll"]
ht_collstmt := stmts["ht_coll"]
var home_posts []*Hp
var home_thumbs []*Ht
hp_rows, err := hp_collstmt.Query()
Err_check(err)
defer hp_rows.Close()
for hp_rows.Next() {
var chp Hp
err = hp_rows.Scan(&chp.BoardN, &chp.Id, &chp.ContentFull, &chp.Content, &chp.Parent, &chp.Password)
Err_check(err)
home_posts = append(home_posts, &chp)
}
ht_rows, err := ht_collstmt.Query()
Err_check(err)
defer ht_rows.Close()
for ht_rows.Next() {
var cht Ht
err = ht_rows.Scan(&cht.BoardN, &cht.Id, &cht.Parent, &cht.Imgprev, &cht.Password)
Err_check(err)
home_thumbs = append(home_thumbs, &cht)
}
return home_posts, home_thumbs
}
func Build_catalog(board string) {
cattemp := template.New("catalog.html").Funcs(catfuncmap)
cattemp, err := cattemp.ParseFiles(BP + "/templates/catalog.html")
Err_check(err)
path := BP + "head/" + board + "/"
Dir_check(path)
f, err := os.Create(path + "catalog.html")
Err_check(err)
defer f.Close()
posts, subjects := get_cat_posts(board)
catalog := Catalog{Name: board, Desc: Board_map[board],Posts: posts, Subjects: subjects,
Header: Board_names, HeaderDescs: Board_descs, SThemes: Themes}
cattemp.Execute(f, catalog)
}
func Build_home() {
hometemp := template.New("home.html").Funcs(catfuncmap)
hometemp, err := hometemp.ParseFiles(BP + "/templates/home.html")
Err_check(err)
path := BP + "head/"
Dir_check(path)
f, err := os.Create(path + "index.html")
Err_check(err)
defer f.Close()
hps, hts := get_home()
home := Home{Title: SiteName, Latest: hps, Thumbs: hts, Header: Board_names, HeaderDescs: Board_descs,
SThemes: Themes}
hometemp.Execute(f, home)
}