mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 07:36:23 -07:00
Continue on the documenting adventure, change paginate to no longer return the original array in the first position of the returned 2d array, added gte and lte to template functions, fixed board page template in order to make Previous button from 1.html work.
This commit is contained in:
parent
a2cdd2b2ec
commit
ec3a49e9e5
4 changed files with 24 additions and 7 deletions
|
@ -169,10 +169,12 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
|||
deleteMatchingFiles(path.Join(config.DocumentRoot, board.Dir), "\\.html$")
|
||||
board.NumPages = len(thread_pages) - 1
|
||||
for page_num, page_threads := range thread_pages {
|
||||
// Package up board info for the template to use.
|
||||
board.CurrentPage = page_num
|
||||
boardinfo_i = nil
|
||||
boardinfo_i = append(boardinfo_i, board)
|
||||
|
||||
// Package up boards, sections, threads, the boardinfo for the template to use.
|
||||
interfaces = nil
|
||||
interfaces = append(interfaces, config,
|
||||
&Wrapper{IName: "boards", Data: all_boards},
|
||||
|
@ -181,6 +183,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
|||
&Wrapper{IName: "boardinfo", Data: boardinfo_i})
|
||||
wrapped := &Wrapper{IName: "boardpage", Data: interfaces}
|
||||
|
||||
// Write to board.html for the first page.
|
||||
if board.CurrentPage == 0 {
|
||||
current_page_file, err = os.OpenFile(path.Join(config.DocumentRoot, board.Dir, "board.html"), os.O_CREATE|os.O_RDWR, 0777)
|
||||
} else {
|
||||
|
@ -191,6 +194,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
|||
error_log.Println(err.Error())
|
||||
}
|
||||
|
||||
// Run the template, pointing it to the file, and passing in the data required.
|
||||
err = img_boardpage_tmpl.Execute(current_page_file, wrapped)
|
||||
if err != nil {
|
||||
html += "Failed building /" + board.Dir + "/: " + err.Error() + "<br />\n"
|
||||
|
@ -203,6 +207,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
|||
return
|
||||
}
|
||||
|
||||
// buildThreads builds thread(s) given a boardid, or if all = false, also given a threadid.
|
||||
func buildThreads(all bool, boardid, threadid int) (html string) {
|
||||
// TODO: detect which page will be built and only build that one and the board page
|
||||
// if all is set to true, ignore which, otherwise, which = build only specified boardid
|
||||
|
@ -224,6 +229,7 @@ func buildThreads(all bool, boardid, threadid int) (html string) {
|
|||
return
|
||||
}
|
||||
|
||||
// buildThreadPages builds the pages for a thread given by a PostTable object.
|
||||
func buildThreadPages(op *PostTable) (html string) {
|
||||
fmt.Printf("OP: %d\n", op.ID)
|
||||
var board_dir string
|
||||
|
|
|
@ -40,9 +40,15 @@ var funcMap = template.FuncMap{
|
|||
"gt": func(a int, b int) bool {
|
||||
return a > b
|
||||
},
|
||||
"gte": func(a int, b int) bool {
|
||||
return a >= b
|
||||
},
|
||||
"lt": func(a int, b int) bool {
|
||||
return a < b
|
||||
},
|
||||
"lte": func(a int, b int) bool {
|
||||
return a <= b
|
||||
},
|
||||
"makeLoop": func(n int) []struct{} {
|
||||
return make([]struct{}, n)
|
||||
},
|
||||
|
|
|
@ -72,8 +72,9 @@ func byteByByteReplace(input, from, to string) string {
|
|||
return input
|
||||
}
|
||||
|
||||
func deleteMatchingFiles(root, match string) (int, error) {
|
||||
files_deleted := 0
|
||||
// Deletes files in a folder (root) that match a given regular expression.
|
||||
// Returns the number of files that were deleted, and any error encountered.
|
||||
func deleteMatchingFiles(root, match string) (files_deleted int, err error) {
|
||||
files, err := ioutil.ReadDir(root)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -259,7 +260,7 @@ func paginate(interface_length int, interf []interface{}) [][]interface{} {
|
|||
var paginated_interfaces [][]interface{}
|
||||
num_arrays := len(interf) / interface_length
|
||||
interfaces_remaining := len(interf) % interface_length
|
||||
paginated_interfaces = append(paginated_interfaces, interf)
|
||||
//paginated_interfaces = append(paginated_interfaces, interf)
|
||||
current_interface := 0
|
||||
for l := 0; l < num_arrays; l++ {
|
||||
paginated_interfaces = append(paginated_interfaces,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="UTF-8">
|
||||
<title>{{$board.Title}}</title>
|
||||
<script type="text/javascript" src="/javascript/jquery-1.10.2.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
@ -43,7 +43,7 @@
|
|||
<tr><th class="postblock">Password</th><td><input type="password" id="postpassword" name="postpassword" size="14" /> (for post/file deletion)</td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
<hr />
|
||||
<div id="content">
|
||||
|
@ -86,7 +86,7 @@
|
|||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{{end}}
|
||||
</div>
|
||||
<hr />
|
||||
|
@ -105,8 +105,12 @@
|
|||
<form method="GET" action="{{$config.SiteWebfolder}}{{$board.Dir}}/{{subtract $board.CurrentPage 1}}.html">
|
||||
<input type="submit" value="Previous" />
|
||||
</form>
|
||||
{{else if intEq $board.CurrentPage 1}}
|
||||
<form method="GET" action="{{$config.SiteWebfolder}}{{$board.Dir}}/">
|
||||
<input type="submit" value="Previous" />
|
||||
</form>
|
||||
{{else}}Previous{{end}}</td>
|
||||
|
||||
|
||||
<td>[<a href="{{$config.SiteWebfolder}}{{$board.Dir}}/">Index</a>]{{range $i,$_ := makeLoop $board.NumPages}} [{{if eq $i $board.CurrentPage}}<b>{{end}}<a href="{{$config.SiteWebfolder}}{{$board.Dir}}/{{add $i 1}}.html">{{add $i 1}}</a>{{if eq $i $board.CurrentPage}}</b>{{end}}]{{end}}</td>
|
||||
<td>{{if lt $board.CurrentPage $board.NumPages}}
|
||||
<form method="GET" action="{{$config.SiteWebfolder}}{{$board.Dir}}/{{add $board.CurrentPage 1}}.html">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue