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

Skip to content

Commit c85827a

Browse files
committed
sitemap 图书
1 parent c51fb89 commit c85827a

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

config/db.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,16 @@ CREATE TABLE IF NOT EXISTS `advertisement` (
437437
PRIMARY KEY (`id`)
438438
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '广告表';
439439

440-
CREATE TABLE IF NOT EXISTS `page_ad` (
441-
`id` int unsigned NOT NULL AUTO_INCREMENT,
440+
CREATE TABLE `page_ad` (
441+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
442442
`path` varchar(31) NOT NULL DEFAULT '' COMMENT '页面路径',
443-
`ad_id` int unsigned NOT NULL DEFAULT 0 COMMENT '广告ID',
443+
`ad_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告ID',
444444
`position` varchar(15) NOT NULL DEFAULT '' COMMENT '广告在页面的位置,英文字符串',
445-
`is_online` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否在线:0-下线;1-在线',
445+
`is_online` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '是否在线:0-下线;1-在线',
446446
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
447-
PRIMARY KEY (`id`)
448-
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '页面广告管理表';
447+
PRIMARY KEY (`id`),
448+
KEY `idx_path` (`path`)
449+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='页面广告管理表';
449450

450451
CREATE TABLE IF NOT EXISTS `friend_link` (
451452
`id` int unsigned NOT NULL AUTO_INCREMENT,

src/logic/sitemap.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,37 @@ func GenSitemap() {
190190
little = 1
191191
large = little + step
192192

193+
// 图书
194+
books := make([]*model.Book, 0)
195+
for {
196+
sitemapFile := "sitemap_book_" + strconv.Itoa(large) + ".xml"
197+
198+
err = MasterDB.Where("id BETWEEN ? AND ?", little, large).Select("id,mtime").Find(&books)
199+
little, large = large+1, little+step
200+
201+
if err != nil {
202+
continue
203+
}
204+
205+
if len(books) == 0 {
206+
break
207+
}
208+
209+
data := map[string]interface{}{
210+
"home": home,
211+
"books": books,
212+
}
213+
214+
if err = output(sitemapFile, data); err == nil {
215+
sitemapFiles = append(sitemapFiles, sitemapFile)
216+
}
217+
218+
books = make([]*model.Book, 0)
219+
}
220+
221+
little = 1
222+
large = little + step
223+
193224
// wiki
194225
wikis := make([]*model.Wiki, 0)
195226
for {

template/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{define "title"}}首页{{end}}
2-
{{define "seo"}}<meta name="keywords" content="{{.setting.Name}},社区,资源,文章,图书,开源项目,{{.setting.SeoKeywords}}">
2+
{{define "seo"}}<meta name="keywords" content="{{.setting.Name}},{{.setting.SeoKeywords}},社区,资源,文章,图书,开源项目">
33
<meta name="description" content="{{.setting.SeoDescription}}">{{end}}
44
{{define "content"}}
55
<div class="row">

template/sitemap.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
<lastmod>{{time_format .Mtime}}</lastmod>
3131
<changefreq>monthly</changefreq>
3232
<priority>0.6</priority>
33+
</url>{{end}}{{range .books}}
34+
<url>
35+
<loc>{{$.home.loc}}/book/{{.Id}}</loc>
36+
<lastmod>{{time_format .Mtime}}</lastmod>
37+
<changefreq>monthly</changefreq>
38+
<priority>0.6</priority>
3339
</url>{{end}}{{range .wiki}}
3440
<url>
3541
<loc>{{$.home.loc}}/wiki/{{.Uri}}</loc>

0 commit comments

Comments
 (0)