Skip to content

Commit

Permalink
Switch to html/template.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertabcd committed Apr 24, 2018
1 parent 8add7f3 commit f84eaa6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion atomfeed/atomfeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package atomfeed
import (
"bytes"
"fmt"
"text/template"
"html/template"
"time"

"github.com/ptt/pttweb/pttbbs"
Expand Down
9 changes: 5 additions & 4 deletions page/pages.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package page

import (
"html/template"
"net/http"

manpb "github.com/ptt/pttweb/proto/man"
Expand Down Expand Up @@ -83,8 +84,8 @@ type BbsArticle struct {
Description string
Board *pttbbs.Board
FileName string
ContentHtml string
ContentTailHtml string
Content template.HTML
ContentTail template.HTML
ContentTruncated bool
PollUrl string
LongPollUrl string
Expand All @@ -106,8 +107,8 @@ type ManArticle struct {
Description string
Board *pttbbs.Board
Path string
ContentHtml string
ContentTailHtml string
Content template.HTML
ContentTail template.HTML
ContentTruncated bool
}

Expand Down
2 changes: 1 addition & 1 deletion page/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package page

import (
"errors"
"html/template"
"net/http"
"path/filepath"
"text/template"
)

type TemplateMap map[string]*template.Template
Expand Down
10 changes: 5 additions & 5 deletions pttweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"flag"
"fmt"
"html/template"
"log"
"net"
"net/http"
Expand All @@ -17,7 +18,6 @@ import (
"path/filepath"
"strconv"
"strings"
"text/template"
"time"

"google.golang.org/grpc"
Expand Down Expand Up @@ -663,8 +663,8 @@ func handleArticleCommon(c *Context, w http.ResponseWriter, brdname, filename st
Description: ar.PreviewContent,
Board: brd,
FileName: filename,
ContentHtml: string(ar.ContentHtml),
ContentTailHtml: string(ar.ContentTailHtml),
Content: template.HTML(string(ar.ContentHtml)),
ContentTail: template.HTML(string(ar.ContentTailHtml)),
ContentTruncated: ar.IsTruncated,
PollUrl: pollUrl,
LongPollUrl: longPollUrl,
Expand Down Expand Up @@ -905,8 +905,8 @@ func handleManArticle(c *Context, w http.ResponseWriter, brd *pttbbs.Board, path
Description: ar.PreviewContent,
Board: brd,
Path: path,
ContentHtml: string(ar.ContentHtml),
ContentTailHtml: string(ar.ContentTailHtml),
Content: template.HTML(string(ar.ContentHtml)),
ContentTail: template.HTML(string(ar.ContentTailHtml)),
ContentTruncated: ar.IsTruncated,
})
}
Expand Down
33 changes: 17 additions & 16 deletions tmpl_funcs.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
package main

import (
"html/template"
"strconv"

"github.com/ptt/pttweb/pttbbs"
)

func colored_counter(num int) string {
func colored_counter(num int) template.HTML {
switch {
case num >= 100:
return `<span class="hl f1">爆</span>`
return template.HTML(`<span class="hl f1">爆</span>`)
case num >= 10:
return `<span class="hl f3">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f3">` + strconv.Itoa(num) + `</span>`)
case num > 0:
return `<span class="hl f2">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f2">` + strconv.Itoa(num) + `</span>`)
case num > -10:
return ""
case num > -100:
return `<span class="hl f0">X` + strconv.Itoa(-num/10) + `</span>`
return template.HTML(`<span class="hl f0">X` + strconv.Itoa(-num/10) + `</span>`)
default:
return `<span class="hl f0">XX</span>`
return template.HTML(`<span class="hl f0">XX</span>`)
}
}

func decorate_board_nuser(num int) string {
func decorate_board_nuser(num int) template.HTML {
switch {
case num < 1:
return ""
case num <= 10:
return strconv.Itoa(num)
return template.HTML(strconv.Itoa(num))
case num <= 50:
return `<span class="hl f3">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f3">` + strconv.Itoa(num) + `</span>`)
case num < 2000:
return `<span class="hl">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl">` + strconv.Itoa(num) + `</span>`)
case num < 5000:
return `<span class="hl f1">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f1">` + strconv.Itoa(num) + `</span>`)
case num < 10000:
return `<span class="hl f4">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f4">` + strconv.Itoa(num) + `</span>`)
case num < 30000:
return `<span class="hl f6">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f6">` + strconv.Itoa(num) + `</span>`)
case num < 60000:
return `<span class="hl f2">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f2">` + strconv.Itoa(num) + `</span>`)
case num < 100000:
return `<span class="hl f3">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f3">` + strconv.Itoa(num) + `</span>`)
default:
return `<span class="hl f5">` + strconv.Itoa(num) + `</span>`
return template.HTML(`<span class="hl f5">` + strconv.Itoa(num) + `</span>`)
}
}

Expand Down

0 comments on commit f84eaa6

Please sign in to comment.