MCPcopy Create free account
hub / github.com/TruthHun/BookStack / SitemapUpdate

Function SitemapUpdate

models/base.go:120–191  ·  view source on GitHub ↗
(domain string)

Source from the content-addressed store, hash-verified

118}
119
120func SitemapUpdate(domain string) {
121 var (
122 files []string
123 bookIds []interface{}
124 bookMap = make(map[int]string)
125 Sitemap = sitemap.NewSitemap("1.0", "utf-8")
126 o = orm.NewOrm()
127 si []sitemap.SitemapIndex
128 )
129 domain = strings.TrimSuffix(domain, "/")
130 os.Mkdir("sitemap", os.ModePerm)
131 //查询公开的书籍
132 qsBooks := o.QueryTable("md_books").Filter("privately_owned", 0)
133 limit := 10000
134 for i := 0; i < 10; i++ {
135 var books []Book
136 qsBooks.Limit(limit).Offset(i*limit).All(&books, "book_id", "identify", "release_time", "book_name")
137 if len(books) > 0 {
138 file := "sitemap/books-" + strconv.Itoa(i) + ".xml"
139 files = append(files, file)
140 var su []sitemap.SitemapUrl
141 for _, book := range books {
142 su = append(su, sitemap.SitemapUrl{
143 Loc: domain + beego.URLFor("DocumentController.Index", ":key", book.Identify),
144 Lastmod: book.ReleaseTime.Format("2006-01-02 15:04:05"),
145 ChangeFreq: sitemap.WEEKLY,
146 Priority: 0.9,
147 })
148 bookIds = append(bookIds, book.BookId)
149 bookMap[book.BookId] = book.Identify
150 }
151 Sitemap.CreateSitemapContent(su, file)
152 } else {
153 i = 10
154 }
155 }
156 qsDocs := o.QueryTable("md_documents").Filter("book_id__in", bookIds...)
157 for i := 0; i < 100; i++ {
158 var docs []Document
159 qsDocs.Limit(limit).Offset(i*limit).All(&docs, "modify_time", "book_id", "document_name", "document_id", "identify")
160 if len(docs) > 0 {
161 file := "sitemap/docs-" + strconv.Itoa(i) + ".xml"
162 files = append(files, file)
163 var su []sitemap.SitemapUrl
164 for _, doc := range docs {
165 bookIdentify := ""
166 if idtf, ok := bookMap[doc.BookId]; ok {
167 bookIdentify = idtf
168 }
169 su = append(su, sitemap.SitemapUrl{
170 Loc: domain + beego.URLFor("DocumentController.Read", ":key", bookIdentify, ":id", url.QueryEscape(doc.Identify)),
171 Lastmod: doc.ModifyTime.Format("2006-01-02 15:04:05"),
172 ChangeFreq: sitemap.WEEKLY,
173 Priority: 0.9,
174 })
175 }
176 Sitemap.CreateSitemapContent(su, file)
177 } else {

Callers 1

SitemapMethod · 0.92

Calls 2

appendFunction · 0.50
AllMethod · 0.45

Tested by

no test coverage detected