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

Method SplitMarkdownAndStore

models/document.go:719–765  ·  view source on GitHub ↗

markdown 文档拆分

(seg string, markdown string, docId int)

Source from the content-addressed store, hash-verified

717
718// markdown 文档拆分
719func (m *Document) SplitMarkdownAndStore(seg string, markdown string, docId int) (err error) {
720 m, err = m.Find(docId)
721 if err != nil {
722 return
723 }
724 identifyFmt := "spilt.%v." + m.Identify
725
726 markdowns := utils.SplitMarkdown(seg, markdown)
727 for idx, md := range markdowns {
728 if !strings.Contains(md, "[TOC]") {
729 md = "[TOC]\n\n" + md
730 }
731
732 doc := NewDocument()
733 doc.Identify = fmt.Sprintf(identifyFmt, idx)
734 if idx == 0 { //不需要使用新标识
735 doc = m
736 } else {
737 doc.OrderSort = idx
738 doc.ParentId = m.DocumentId
739 }
740 doc.Release = ""
741 doc.BookId = m.BookId
742 doc.Markdown = md
743 doc.DocumentName = utils.ParseTitleFromMdHtml(mdtil.Md2html(md))
744 doc.Version = time.Now().Unix()
745 doc.MemberId = m.MemberId
746
747 if !strings.Contains(doc.Markdown, "[TOC]") {
748 doc.Markdown = "[TOC]\r\n" + doc.Markdown
749 }
750
751 if docId, err := doc.InsertOrUpdate(); err != nil {
752 beego.Error("InsertOrUpdate => ", err)
753 } else {
754 var ds = DocumentStore{
755 DocumentId: int(docId),
756 Markdown: doc.Markdown,
757 }
758 if err := ds.InsertOrUpdate(ds, "markdown"); err != nil {
759 beego.Error(err)
760 }
761 }
762
763 }
764 return
765}
766
767// IsAllowReadChapter 书籍章节是否允许阅读
768func (m *Document) IsAllowReadChapter(bookId int, docId int) (yes bool, percent int) {

Callers 1

ContentMethod · 0.80

Calls 5

FindMethod · 0.95
InsertOrUpdateMethod · 0.95
SplitMarkdownFunction · 0.92
ParseTitleFromMdHtmlFunction · 0.92
NewDocumentFunction · 0.85

Tested by

no test coverage detected