-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbsmenu.go
102 lines (90 loc) · 2.76 KB
/
bbsmenu.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
package gochan
import (
"encoding/json"
"fmt"
"time"
)
type bbsmenu_s struct {
Description string `json:"description"`
MenuList []menu_list `json:"menu_list"`
LastModify int `json:"last_modify"`
LastModifyString string `json:"last_modify_string"`
}
type menu_list struct {
CategoryName string `json:"category_name"`
CategoryContent []category_content `json:"category_content"`
CategoryTotal int `json:"category_total"`
CategoryNumber string `json:"category_number"`
}
type category_content struct {
URL string `json:"url"`
CategoryName string `json:"category_name"`
Category int `json:"category"`
BoardName string `json:"board_name"`
CategoryOrder int `json:"category_order"`
DirectoryName string `json:"directory_name"`
}
type BBSMENU struct {
HTML, JSON string
lastmod time.Time
}
func (sv *Server) GenBBSmenu() error {
if sv == nil || sv.boards == nil {
return ErrInvalidServer
}
var bbsmenu bbsmenu_s
sv.BBSMENU.lastmod = time.Now()
bbsmenu.Description = sv.Description
bbsmenu.LastModify = int(sv.BBSMENU.lastmod.Unix())
bbsmenu.LastModifyString = sv.BBSMENU.lastmod.Format("2006/01/02(Mon) 15:04:05.00")
list_map := make(map[string]*menu_list)
for _, board := range sv.boards {
var cont category_content
cont.URL = board.URL()
cont.CategoryName = "その他"
cont.BoardName = board.Title()
cont.DirectoryName = board.BBS()
if s, err := board.Conf.GetString("CATEGORY"); err == nil {
cont.CategoryName = s
}
if _, ok := list_map[cont.CategoryName]; !ok {
list_map[cont.CategoryName] = &menu_list{
CategoryName: cont.CategoryName,
}
}
list_map[cont.CategoryName].CategoryContent = append(list_map[cont.CategoryName].CategoryContent, cont)
}
i := 1
for s, list := range list_map {
for n, cont := range list.CategoryContent {
cont.CategoryOrder = n
cont.Category = i
}
list.CategoryName = s
list.CategoryNumber = fmt.Sprint(i)
list.CategoryTotal = len(list.CategoryContent)
bbsmenu.MenuList = append(bbsmenu.MenuList, *list)
}
tmp, err := json.Marshal(bbsmenu)
if err != nil {
return err
}
sv.BBSMENU.JSON = string(tmp)
sv.BBSMENU.HTML = `<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<TITLE>` + bbsmenu.Description + `</TITLE>
</HEAD>
<BODY>` + bbsmenu.Description
for _, list := range bbsmenu.MenuList {
sv.BBSMENU.HTML += `<br><br><B>` + list.CategoryName + `</B><br>`
for _, c := range list.CategoryContent {
sv.BBSMENU.HTML += `<A HREF=` + c.URL + `>` + c.BoardName + `</A><br>`
}
}
sv.BBSMENU.HTML += `
<br><br>更新日 ` + sv.BBSMENU.lastmod.Format("2006/01/02") + `</BODY>
</HTML>`
sv.BBSMENU.HTML = toSJIS(sv.BBSMENU.HTML)
return nil
}