Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc2260c

Browse files
committed
首页图书
1 parent aa864ed commit fc2260c

File tree

5 files changed

+51
-97
lines changed

5 files changed

+51
-97
lines changed

src/http/controller/index.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"html/template"
1212
"logic"
13+
"math/rand"
1314
"model"
1415
"net/http"
1516
"net/url"
@@ -60,7 +61,12 @@ func (IndexController) Index(ctx echo.Context) error {
6061
// Golang 资源
6162
resources := logic.DefaultResource.FindBy(ctx, 10)
6263

63-
return render(ctx, "index.html", map[string]interface{}{"topics": topicsList, "articles": recentArticles, "likeflags": likeFlags, "resources": resources})
64+
books := logic.DefaultGoBook.FindBy(ctx, 24)
65+
bookNum := 8
66+
bookStart := rand.Intn(len(books) - bookNum)
67+
books = books[bookStart : bookStart+bookNum]
68+
69+
return render(ctx, "index.html", map[string]interface{}{"topics": topicsList, "articles": recentArticles, "likeflags": likeFlags, "resources": resources, "books": books})
6470
}
6571

6672
// WrapUrl 包装链接

static/css/index.css

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
.recent-list {}
88
.article-list { margin-top: 20px; margin-bottom: 20px;}
99

10-
.recent-list .title, .article-list .title {position: relative; border-bottom: 1px solid #ccc;}
11-
.recent-list .title h3, .article-list .title h3 { line-height: 24px;font-size: 14px; font-weight: bold; display: inline-block; margin-bottom: 4px; margin-top: 10px;}
12-
.recent-list .title h3 a, .article-list .title h3 a {text-decoration: none;color: #666;}
13-
.recent-list .title .more, .article-list .title .more { position: absolute; right: 3px;top: 16px;font-size: 10pt; text-decoration: none;}
10+
.recent-list .title, .article-list .title, .book-list .title {position: relative; border-bottom: 1px solid #ccc;}
11+
.recent-list .title h3, .article-list .title h3, .book-list .title h3 { line-height: 24px;font-size: 14px; font-weight: bold; display: inline-block; margin-bottom: 4px; margin-top: 10px;}
12+
.recent-list .title h3 a, .article-list .title h3 a, .book-list .title h3 a {text-decoration: none;color: #666;}
13+
.recent-list .title .more, .article-list .title .more, .book-list .title .more { position: absolute; right: 3px;top: 16px;font-size: 10pt; text-decoration: none;}
1414
.recent-list ul {padding-top: 5px;}
1515
.recent-list ul li {height: 22px;line-height: 22px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px #c2d5e3 dashed;margin-bottom: 5px;padding-bottom: 5px;}
1616
.recent-list ul li i {float: left;width: 4px;height: 4px;background: #858585;margin-top: 10px;margin-right: 7px;}
1717
.recent-list ul li a {text-decoration: none;}
1818
.recent-list ul li a:hover {text-decoration: underline; color: #d54f4b;}
1919

20-
.article-list .title {margin-left: 15px; margin-right: 15px;}
20+
.article-list .title, .book-list .title {margin-left: 15px; margin-right: 15px;}
2121
.article-list .article-bottom { margin-bottom: 15px; margin-right: 15px; margin-top: -12px; font-size: 10pt;}
2222

2323
.learn-info {}
@@ -30,6 +30,13 @@
3030
.learn-info .infolist ul li a.learn:hover {text-decoration: none;color: #FF0000;}
3131
.learn-info ul li i {float: left;width: 4px;height: 4px;background: #858585;margin-top: 10px;margin-right: 7px;}
3232

33+
.book-list { margin-bottom: 15px; }
34+
.book-list ul { overflow: hidden; }
35+
.book-list .book-item { margin: 10px 18px; float: left; }
36+
.book-list .book-item .book-img { width: 180px; margin: 0 auto; }
37+
.book-list .book-item .book-img img { border: 1px solid #fff; box-shadow: 1px 1px 6px rgba(0, 0, 0, 0.7); -webkit-box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.7); -moz-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7); display: block; max-width: 100%; vertical-align: middle; }
38+
.book-list .book-item .book-title { width: 160px; margin: 0 auto; text-align: center; overflow: hidden; white-space: nowrap; }
39+
3340
.sidebar {margin-left: 0px;}
3441
.sidebar .box {padding: 10px;margin: 0 0 20px 0;-webkit-border-radius: 6px;-moz-border-radius: 6px;border-radius: 6px;-webkit-box-shadow: 0 0px 2px rgba(0,0,0,0.05);-moz-box-shadow: 0 0px 2px rgba(0,0,0,0.1);box-shadow: 0 0px 2px rgba(0,0,0,0.05); clear:both;}
3542
.sidebar .avatar-area, .sidebar .profile-show { margin-left: 20px; }

template/books/detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<div class="col-lg-2 col-md-2">
1717
<div class="book-cover-col">
1818
<div class="book-cover-box wide">
19-
<a href="{{if .book.Cover}}{{.book.Cover}}{{else}}http://studygolang.qiniudn.com/img/nocover.png{{end}}" style="float: none;">
20-
<img src="{{if .book.Cover}}{{.book.Cover}}{{else}}http://studygolang.qiniudn.com/img/nocover.png{{end}}" class="bookcover">
19+
<a href="{{if .book.Cover}}{{.book.Cover}}{{else}}http://studygolang.qiniudn.com/img/golang_default_cover.png{{end}}" style="float: none;">
20+
<img src="{{if .book.Cover}}{{.book.Cover}}{{else}}http://studygolang.qiniudn.com/img/golang_default_cover.png{{end}}" class="bookcover">
2121
</a>
2222
<span class="ebook"></span>
2323
</div>

template/books/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ <h4><a href="/book/{{.Id}}" target="_blank" title="{{.Name}}">{{.Name}}</a></h4>
3535
</div>
3636
<div class="col-md-2 col-sm-2 book-cover-box">
3737
<a href="/book/{{.Id}}" target="_blank" title="{{.Name}}">
38-
<img class="lazy" src="{{if .Cover}}{{.Cover}}{{else}}http://studygolang.qiniudn.com/img/nocover.png{{end}}" alt="{{.Name}}" style="display: inline;">
38+
<img class="lazy" src="{{if .Cover}}{{.Cover}}{{else}}http://studygolang.qiniudn.com/img/golang_default_cover.png{{end}}" alt="{{.Name}}" style="display: inline;">
3939
</a>
4040
</div>
4141
</div>

template/index.html

Lines changed: 29 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,31 @@ <h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">
109109
<div class="pull-right article-bottom"><a href="/articles?lastid={{add $article.Id -10}}" title="查看更多">查看更多&gt;&gt;</a></div>
110110
{{end}}
111111
</div>
112+
<div class="row box_white book-list">
113+
<div class="title">
114+
<h3><a href="/books">图书</a></h3>
115+
<a class="pull-right more" href="/books">更多&gt;&gt;</a>
116+
</div>
117+
<ul class="list-unstyled">
118+
{{range .books}}
119+
<li class="book-item">
120+
<div class="book-img">
121+
<a href="/book/{{.Id}}" title="{{.Name}}">
122+
<img src="{{if .Cover}}{{.Cover}}{{else}}http://studygolang.qiniudn.com/img/golang_default_cover.png{{end}}" width="180px" height="225px" alt="{{.Name}}">
123+
</a>
124+
</div>
125+
<div class="book-title">
126+
<h5>{{.Name}}</h5>
127+
</div>
128+
</li>
129+
{{end}}
130+
</ul>
131+
</div>
132+
112133
<div class="row box_white learn-info">
113134
<h3><a href="javascript:">学习资料</a></h3>
114135
<div class="col-md-6 infolist">
115136
<ul class="list-unstyled">
116-
<li>
117-
<i></i>
118-
<a href="http://www.ucai.cn/course/show/69" title="Go编程基础(无闻)" target="_blank" class="video">【视频】《Go编程基础(无闻)》</a>
119-
<a href="http://www.ucai.cn/course/chapter/69/3210/4555" target="_blank" class="learn pull-right">开始学习&gt;&gt;</a>
120-
</li>
121-
<li>
122-
<i></i>
123-
<a href="http://www.ucai.cn/course/show/87" title="Go Web基础(无闻)" target="_blank" class="video">【视频】《Go Web基础(无闻)》</a>
124-
<a href="http://www.ucai.cn/course/chapter/87/3267/4710" target="_blank" class="learn pull-right">开始学习&gt;&gt;</a>
125-
</li>
126-
<li>
127-
<i></i>
128-
<a href="http://www.ucai.cn/course/show/134" title="Go 名库讲解(无闻)" target="_blank" class="video">【视频】《Go 名库讲解(无闻)》</a>
129-
<a href="http://www.ucai.cn/course/chapter/134/3699/6825" target="_blank" class="learn pull-right">开始学习&gt;&gt;</a>
130-
</li>
131137
<li>
132138
<i></i>
133139
<a href="http://www.ucai.cn/course/show/26" title="Go 语言语法与特性教程(陈皓)" target="_blank" class="video">【文本】《Go 语言语法与特性教程(陈皓)》</a>
@@ -148,89 +154,24 @@ <h3><a href="javascript:">学习资料</a></h3>
148154
<a href="http://www.ucai.cn/course/show/22" title="Go 语言入门教程" target="_blank" class="video">【文本】《Go 语言入门教程》</a>
149155
<a href="http://www.ucai.cn/course/chapter/22/2887/2927" target="_blank" class="learn pull-right">开始学习&gt;&gt;</a>
150156
</li>
151-
<li>
152-
<i></i>
153-
<a href="http://product.china-pub.com/3804180" title="Go并发编程实la" target="_blank" class="video">【图书】《Go并发编程实战 — 郝林》</a>
154-
<a href="http://product.china-pub.com/3804180" target="_blank" class="learn pull-right">查看详情&gt;&gt;</a>
155-
</li>
156-
<li>
157-
<i></i>
158-
<a href="http://book.douban.com/subject/19897704/" title="An Introduction to Programming in Go" target="_blank" class="video">【图书】《An Introduction to Programming in Go》</a>
159-
<a href="http://book.douban.com/subject/19897704/" target="_blank" class="learn pull-right">详情&gt;&gt;</a>
160-
</li>
161-
<li>
162-
<i></i>
163-
<a href="https://github.com/tiancaiamao/go-internals" title="深入解析Go — tiancaiamao" target="_blank" class="video">【图书】《深入解析Go — tiancaiamao》</a>
164-
<a href="https://github.com/tiancaiamao/go-internals/blob/master/ebook/preface.md" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
165-
</li>
166-
<li>
167-
<i></i>
168-
<a href="https://github.com/astaxie/Go-in-Action" title="Go实战开发 — astaxie" target="_blank" class="video">【图书】《Go实战开发 — astaxie》</a>
169-
<a href="https://github.com/astaxie/Go-in-Action/blob/master/ebook/zh/preface.md" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
170-
</li>
171-
<li>
172-
<i></i>
173-
<a href="https://github.com/achun/Go-Blog-In-Action" title="Go语言博客实践 — achun" target="_blank" class="video">【图书】《Go语言博客实践 — achun》</a>
174-
<a href="https://github.com/achun/Go-Blog-In-Action" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
175-
</li>
176157
</ul>
177158
</div>
178159
<div class="col-md-6 infolist">
179160
<ul class="list-unstyled">
180161
<li>
181162
<i></i>
182-
<a href="https://github.com/qyuhen/book" title="Go 学习笔记 第三版 — 雨痕" target="_blank" class="video">【图书】《Go 学习笔记 第三版 — 雨痕》</a>
183-
<a href="https://github.com/qyuhen/book/blob/master/Go%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%20%E7%AC%AC%E4%B8%89%E7%89%88.pdf?raw=true" target="_blank" class="learn pull-right">立即下载&gt;&gt;</a>
184-
</li>
185-
<li>
186-
<i></i>
187-
<a href="https://github.com/astaxie/build-web-application-with-golang" title="Go Web 编程 — 谢孟军" target="_blank" class="video">【图书】《Go Web 编程 — 谢孟军》</a>
188-
<a href="https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/preface.md" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
189-
</li>
190-
<li>
191-
<i></i>
192-
<a href="https://github.com/polaris1119/The-Golang-Standard-Library-by-Example" title="Go语言标准库 — polaris" target="_blank" class="video">【图书】《Go语言标准库 — polaris》</a>
193-
<a href="https://github.com/polaris1119/The-Golang-Standard-Library-by-Example/blob/master/preface.md" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
194-
</li>
195-
<li>
196-
<i></i>
197-
<a href="http://book.douban.com/subject/11577300/" title="Go语言编程 — 许式伟等" target="_blank" class="video">【图书】《Go语言编程 — 许式伟等》</a>
198-
<a href="http://book.douban.com/subject/11577300/" target="_blank" class="learn pull-right">查看详情&gt;&gt;</a>
199-
</li>
200-
<li>
201-
<i></i>
202-
<a href="http://book.douban.com/subject/24869910/" title="Go语言程序设计 — Mark Summerfield,许式伟等译" target="_blank" class="video">【图书】《Go语言程序设计 — 许式伟等译》</a>
203-
<a href="http://book.douban.com/subject/24869910/" target="_blank" class="learn pull-right">查看详情&gt;&gt;</a>
204-
</li>
205-
<li>
206-
<i></i>
207-
<a href="http://book.douban.com/subject/25919900/" title="Go语言程序设计 — 王鹏" target="_blank" class="video">【图书】《Go语言程序设计 — 王鹏》</a>
208-
<a href="http://book.douban.com/subject/25919900/" target="_blank" class="learn pull-right">查看详情&gt;&gt;</a>
209-
</li>
210-
<li>
211-
<i></i>
212-
<a href="http://book.douban.com/subject/10770080/" title="Go语言·云动力 — [新加坡] 樊虹剑" target="_blank" class="video">【图书】《Go语言·云动力 — [新加坡] 樊虹剑》</a>
213-
<a href="http://book.douban.com/subject/10770080/" target="_blank" class="learn pull-right">查看详情&gt;&gt;</a>
214-
</li>
215-
<li>
216-
<i></i>
217-
<a href="http://book.douban.com/subject/10558892/" title="The Way to Go — Ivo Balbaert" target="_blank" class="video">【图书】《The Way to Go — Ivo Balbaert》</a>
218-
<a href="http://book.douban.com/subject/10558892/" target="_blank" class="learn pull-right">查看详情&gt;&gt;</a>
219-
</li>
220-
<li>
221-
<i></i>
222-
<a href="https://github.com/Unknwon/the-way-to-go_ZH_CN" title="The Way to Go 中文 — 无闻译" target="_blank" class="video">【图书】《The Way to Go 中文 — 无闻译》</a>
223-
<a href="https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/directory.md" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
163+
<a href="http://www.ucai.cn/course/show/69" title="Go编程基础(无闻)" target="_blank" class="video">【视频】《Go编程基础(无闻)》</a>
164+
<a href="http://www.ucai.cn/course/chapter/69/3210/4555" target="_blank" class="learn pull-right">开始学习&gt;&gt;</a>
224165
</li>
225166
<li>
226167
<i></i>
227-
<a href="https://github.com/astaxie/NPWG_zh" title="Network programming with Go — astaxie等译" target="_blank" class="video">图书】《Network programming with Go</a>
228-
<a href="http://jan.newmarch.name/go/zh/index.html" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
168+
<a href="http://www.ucai.cn/course/show/87" title="Go Web基础(无闻)" target="_blank" class="video">视频】《Go Web基础(无闻)</a>
169+
<a href="http://www.ucai.cn/course/chapter/87/3267/4710" target="_blank" class="learn pull-right">开始学习&gt;&gt;</a>
229170
</li>
230171
<li>
231172
<i></i>
232-
<a href="https://www.gitbook.io/book/codegangsta/building-web-apps-with-go" title="Building Web Apps with Go" target="_blank" class="video">图书】《Building Web Apps with Go</a>
233-
<a href="http://codegangsta.gitbooks.io/building-web-apps-with-go/" target="_blank" class="learn pull-right">开始阅读&gt;&gt;</a>
173+
<a href="http://www.ucai.cn/course/show/134" title="Go 名库讲解(无闻)" target="_blank" class="video">视频】《Go 名库讲解(无闻)</a>
174+
<a href="http://www.ucai.cn/course/chapter/134/3699/6825" target="_blank" class="learn pull-right">开始学习&gt;&gt;</a>
234175
</li>
235176
</ul>
236177
</div>
@@ -399,10 +340,10 @@ <h3 class="title"><i class="glyphicon glyphicon-link"></i>&nbsp;友情链接</h3
399340
</div>
400341
{{end}}
401342
{{define "css"}}
402-
<link href="/static/css/index.css" rel="stylesheet"/>
343+
<link href="/static/css/index.css?v=0.4" rel="stylesheet"/>
403344
{{end}}
404345
{{define "js"}}
405-
<script type="text/javascript" src="/static/js/index.js?v=0.1"></script>
346+
<script type="text/javascript" src="/static/js/index.js?v=0.5"></script>
406347
<script type="text/javascript">
407348
// 需要加载的侧边栏
408349
SG.SIDE_BARS = [

0 commit comments

Comments
 (0)