MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Index

Method Index

controllers/HomeController.go:20–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func (this *HomeController) Index() {
21 //tab
22 var (
23 tab string
24 cid int //分类,如果只是一级分类,则忽略,二级分类,则根据二级分类查找内容
25 urlPrefix = beego.URLFor("HomeController.Index")
26 cate models.Category
27 lang = this.GetString("lang")
28 tabName = map[string]string{"recommend": "网站推荐", "latest": "最新发布", "popular": "热门书籍"}
29 )
30
31 tab = strings.ToLower(this.GetString("tab"))
32 switch tab {
33 case "recommend", "popular", "latest":
34 default:
35 tab = "latest"
36 }
37
38 ModelCate := new(models.Category)
39 cates, _ := ModelCate.GetCates(-1, 1)
40 cid, _ = this.GetInt("cid")
41 pid := cid
42 if cid > 0 {
43 for _, item := range cates {
44 if item.Id == cid {
45 if item.Pid > 0 {
46 pid = item.Pid
47 }
48 this.Data["Cate"] = item
49 cate = item
50 break
51 }
52 }
53 }
54 this.Data["Cates"] = cates
55 this.Data["Cid"] = cid
56 this.Data["Pid"] = pid
57 this.TplName = "home/index.html"
58 this.Data["IsHome"] = true
59
60 pageIndex, _ := this.GetInt("page", 1)
61 //每页显示24个,为了兼容Pad、mobile、PC
62 pageSize := 24
63 books, totalCount, err := models.NewBook().HomeData(pageIndex, pageSize, models.BookOrder(tab), lang, cid)
64 if err != nil {
65 beego.Error(err)
66 this.Abort("404")
67 }
68 if totalCount > 0 {
69 urlSuffix := "&tab=" + tab
70 if cid > 0 {
71 urlSuffix = urlSuffix + "&cid=" + strconv.Itoa(cid)
72 }
73 urlSuffix = urlSuffix + "&lang=" + lang
74 html := utils.NewPaginations(conf.RollPage, totalCount, pageSize, pageIndex, urlPrefix, urlSuffix)
75 this.Data["PageHtml"] = html
76 } else {
77 this.Data["PageHtml"] = ""

Callers

nothing calls this directly

Calls 6

NewBookFunction · 0.92
BookOrderTypeAlias · 0.92
NewPaginationsFunction · 0.92
GetCatesMethod · 0.80
HomeDataMethod · 0.80
GetSeoByPageMethod · 0.80

Tested by

no test coverage detected