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

Function RenderDocumentById

utils/util.go:156–178  ·  view source on GitHub ↗

渲染markdown为html并录入数据库

(id int)

Source from the content-addressed store, hash-verified

154
155// 渲染markdown为html并录入数据库
156func RenderDocumentById(id int) {
157 //使用chromium-browser
158 // chromium-browser --headless --disable-gpu --screenshot --no-sandbox --window-size=320,480 http://www.bookstack.cn
159 link := "http://localhost:" + beego.AppConfig.DefaultString("httpport", "8181") + "/local-render?id=" + strconv.Itoa(id)
160 chrome := beego.AppConfig.DefaultString("chrome", "chromium-browser")
161 chromeArgs := []string{chrome, "--headless", "--disable-gpu", "--screenshot", "--no-sandbox", "--window-size=320,480", link}
162 nodeArgs := []string{"node", "crawl.js", "--url", link}
163 for _, v := range [][]string{chromeArgs, nodeArgs} {
164 cmd := exec.Command(v[0], v[1:]...)
165 beego.Info("render document by document_id:", cmd.Args)
166 // 超过10秒,杀掉进程,避免长期占用
167 time.AfterFunc(httpTimeout, func() {
168 if cmd.Process != nil && cmd.Process.Pid != 0 {
169 cmd.Process.Kill()
170 }
171 })
172 if err := cmd.Run(); err != nil {
173 beego.Error(err)
174 continue
175 }
176 return
177 }
178}
179
180const screenshotCoverJS = `'use strict';
181// 说明: 这段js是用来进行书籍封面截屏的,请勿随便删除或改动

Callers 3

ReleaseContentMethod · 0.92
GenerateBookMethod · 0.92
generateMethod · 0.92

Calls 1

RunMethod · 0.80

Tested by

no test coverage detected