mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-04-05 20:17:53 +08:00
add prev&next in default read.tpl
This commit is contained in:
parent
6054b5f8ba
commit
2988faba87
1707
conf/app.conf.example
Normal file
1707
conf/app.conf.example
Normal file
File diff suppressed because one or more lines are too long
@ -148,8 +148,6 @@ func (c *DocumentController) Read() {
|
||||
identify := c.Ctx.Input.Param(":key")
|
||||
token := c.GetString("token")
|
||||
id := c.GetString(":id")
|
||||
logs.Info(identify)
|
||||
logs.Info(id)
|
||||
|
||||
if identify == "" || id == "" {
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
@ -197,6 +195,41 @@ func (c *DocumentController) Read() {
|
||||
doc.AttachList = attach
|
||||
}
|
||||
|
||||
// prev,next
|
||||
treeJson, err := models.NewDocument().FindDocumentTree2(bookResult.BookId)
|
||||
if err != nil {
|
||||
logs.Error("生成项目文档树时出错 ->", err)
|
||||
}
|
||||
|
||||
res := getTreeRecursive(treeJson, 0)
|
||||
flat := make([]DocumentTreeFlatten, 0)
|
||||
Flatten(res, &flat)
|
||||
var index int
|
||||
for i, v := range flat {
|
||||
if v.Identify == id {
|
||||
index = i
|
||||
}
|
||||
}
|
||||
var PrevName, PrevPath, NextName, NextPath string
|
||||
if index == 0 {
|
||||
c.Data["PrevName"] = "没有了"
|
||||
PrevName = "没有了"
|
||||
} else {
|
||||
c.Data["PrevPath"] = identify + "/" + flat[index-1].Identify
|
||||
c.Data["PrevName"] = flat[index-1].DocumentName
|
||||
PrevPath = identify + "/" + flat[index-1].Identify
|
||||
PrevName = flat[index-1].DocumentName
|
||||
}
|
||||
if index == len(flat)-1 {
|
||||
c.Data["NextName"] = "没有了"
|
||||
NextName = "没有了"
|
||||
} else {
|
||||
c.Data["NextPath"] = identify + "/" + flat[index+1].Identify
|
||||
c.Data["NextName"] = flat[index+1].DocumentName
|
||||
NextPath = identify + "/" + flat[index+1].Identify
|
||||
NextName = flat[index+1].DocumentName
|
||||
}
|
||||
|
||||
doc.IncrViewCount(doc.DocumentId)
|
||||
doc.ViewCount = doc.ViewCount + 1
|
||||
doc.PutToCache()
|
||||
@ -216,7 +249,7 @@ func (c *DocumentController) Read() {
|
||||
data.DocId = doc.DocumentId
|
||||
data.DocIdentify = doc.Identify
|
||||
data.DocTitle = doc.DocumentName
|
||||
data.Body = doc.Release
|
||||
data.Body = doc.Release + "<div class='wiki-bottom-left'>上一篇: <a href='/docs/" + PrevPath + "' rel='prev'>" + PrevName + "</a><br />下一篇: <a href='/docs/" + NextPath + "' rel='next'>" + NextName + "</a><br /></div>"
|
||||
data.Title = doc.DocumentName + " - Powered by MinDoc"
|
||||
data.Version = doc.Version
|
||||
data.ViewCount = doc.ViewCount
|
||||
@ -243,43 +276,6 @@ func (c *DocumentController) Read() {
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.build_doc_tree_error"))
|
||||
}
|
||||
|
||||
// prev,next
|
||||
treeJson, err := models.NewDocument().FindDocumentTree2(bookResult.BookId)
|
||||
// logs.Info(treeJson)
|
||||
res := getTreeRecursive(treeJson, 0)
|
||||
// explain
|
||||
// for i, v := range res {
|
||||
// logs.Info(i, v.Children)
|
||||
// }
|
||||
|
||||
flat := make([]DocumentTreeFlatten, 0)
|
||||
Flatten(res, &flat)
|
||||
// flattened := Flatten(res, &flat)
|
||||
// for i, v := range *flattened {
|
||||
var index int
|
||||
for i, v := range flat {
|
||||
logs.Info(i, v)
|
||||
if v.Identify == id {
|
||||
logs.Info(i, v)
|
||||
index = i
|
||||
}
|
||||
}
|
||||
// logs.Info(flat[index].Identify)
|
||||
// logs.Info(flat[index].Identify)
|
||||
|
||||
if index == 0 {
|
||||
c.Data["PrevName"] = "没有了"
|
||||
} else {
|
||||
c.Data["PrevPath"] = identify + "/" + flat[index-1].Identify
|
||||
c.Data["PrevName"] = flat[index-1].DocumentName
|
||||
}
|
||||
if index == len(flat)-1 {
|
||||
c.Data["NextName"] = "没有了"
|
||||
} else {
|
||||
c.Data["NextPath"] = identify + "/" + flat[index+1].Identify
|
||||
c.Data["NextName"] = flat[index+1].DocumentName
|
||||
}
|
||||
|
||||
c.Data["Description"] = utils.AutoSummary(doc.Release, 120)
|
||||
|
||||
c.Data["Model"] = bookResult
|
||||
@ -296,16 +292,11 @@ func (c *DocumentController) Read() {
|
||||
} else if doc.IsOpen == 2 {
|
||||
c.Data["FoldSetting"] = "empty"
|
||||
}
|
||||
|
||||
// c.Data["json"] = flat
|
||||
// c.ServeJSON()
|
||||
}
|
||||
|
||||
// 递归得到树状结构体
|
||||
func getTreeRecursive(list []*models.DocumentTree, parentId int) (res []*models.DocumentTree) {
|
||||
// res := make([]*models.DocumentTree, 0)
|
||||
for _, v := range list {
|
||||
// logs.Info(v)
|
||||
if v.ParentId == parentId {
|
||||
v.Children = getTreeRecursive(list, v.DocumentId)
|
||||
res = append(res, v)
|
||||
@ -323,15 +314,11 @@ func Flatten(list []*models.DocumentTree, flattened *[]DocumentTreeFlatten) {
|
||||
tree[0].DocumentId = v.DocumentId
|
||||
tree[0].DocumentName = v.DocumentName
|
||||
tree[0].Identify = v.Identify
|
||||
// logs.Info(v.DocumentName)
|
||||
*flattened = append(*flattened, tree...)
|
||||
logs.Info(flattened)
|
||||
if len(v.Children) > 0 {
|
||||
// logs.Info(v.Children)
|
||||
Flatten(v.Children, flattened)
|
||||
}
|
||||
}
|
||||
// return flattened
|
||||
return
|
||||
}
|
||||
|
||||
@ -952,24 +939,30 @@ func (c *DocumentController) Export() {
|
||||
c.Prepare()
|
||||
|
||||
identify := c.Ctx.Input.Param(":key")
|
||||
|
||||
if identify == "" {
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
output := c.GetString("output")
|
||||
token := c.GetString("token")
|
||||
|
||||
logs.Info(identify)
|
||||
logs.Info(output)
|
||||
logs.Info(token)
|
||||
// 如果没有开启匿名访问则跳转到登录
|
||||
if !c.EnableAnonymous && !c.isUserLoggedIn() {
|
||||
logs.Info(output)
|
||||
promptUserToLogIn(c)
|
||||
return
|
||||
}
|
||||
if !conf.GetEnableExport() {
|
||||
logs.Info(output)
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "export_func_disable"))
|
||||
}
|
||||
|
||||
bookResult := models.NewBookResult()
|
||||
if c.Member != nil && c.Member.IsAdministrator() {
|
||||
logs.Info(output)
|
||||
book, err := models.NewBook().FindByIdentify(identify)
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows {
|
||||
@ -981,17 +974,21 @@ func (c *DocumentController) Export() {
|
||||
}
|
||||
bookResult = models.NewBookResult().ToBookResult(*book)
|
||||
} else {
|
||||
logs.Info(output)
|
||||
bookResult = c.isReadable(identify, token)
|
||||
}
|
||||
if !bookResult.IsDownload {
|
||||
logs.Info(output)
|
||||
c.ShowErrorPage(200, i18n.Tr(c.Lang, "message.cur_project_export_func_disable"))
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") {
|
||||
logs.Info(output)
|
||||
bookResult.Cover = conf.URLForWithCdnImage(bookResult.Cover)
|
||||
}
|
||||
|
||||
logs.Info(Markdown)
|
||||
if output == Markdown {
|
||||
logs.Info("hah")
|
||||
if bookResult.Editor != EditorMarkdown && bookResult.Editor != EditorCherryMarkdown {
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.cur_project_not_support_md"))
|
||||
}
|
||||
|
@ -576,6 +576,17 @@ table>tbody>tr:hover {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.manual-article .wiki-bottom-left {
|
||||
border-top: 1px solid #E5E5E5;
|
||||
line-height: 25px;
|
||||
color: #333;
|
||||
text-align: left;
|
||||
font-size: 12px;
|
||||
margin-bottom: 20px;
|
||||
margin-top: 30px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.manual-article .jump-top .view-backtop {
|
||||
position: fixed;
|
||||
bottom: -30px;
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB |
BIN
uploads/202404/cover_17c8260e47e06f18_small.png
Normal file
BIN
uploads/202404/cover_17c8260e47e06f18_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 136 KiB |
BIN
uploads/202404/cover_17c8286be57a8600_small.png
Normal file
BIN
uploads/202404/cover_17c8286be57a8600_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
BIN
uploads/202404/cover_17c829abdef5fdc8.png
Normal file
BIN
uploads/202404/cover_17c829abdef5fdc8.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
uploads/books/2/book.zip
Normal file
BIN
uploads/books/2/book.zip
Normal file
Binary file not shown.
@ -189,12 +189,7 @@
|
||||
<div class="article-content">
|
||||
<div class="article-body {{if eq .Model.Editor "markdown"}}markdown-body editormd-preview-container{{else}}editor-content{{end}}" id="page-content">
|
||||
{{.Content}}
|
||||
<div class="col-xs-12 model sxy">
|
||||
<ul class="row">
|
||||
<div class="post-previous twofifth"> 上一篇: <br><a href='/docs/{{.PrevPath}}' rel='prev'>{{.PrevName}}</a></div>
|
||||
<div class="post-next twofifth"> 下一篇: <br><a href='/docs/{{.NextPath}}' rel='next'>{{.NextName}}</a></div>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- <div class="wiki-bottom-left">上一篇: <a href='/docs/{{.PrevPath}}' rel='prev'>{{.PrevName}}</a><br />下一篇: <a href='/docs/{{.NextPath}}' rel='next'>{{.NextName}}</a><br /></div> -->
|
||||
</div>
|
||||
|
||||
{{if .Model.IsDisplayComment}}
|
||||
@ -372,6 +367,10 @@ $(function () {
|
||||
if (!window.IS_DOCUMENT_INDEX && IS_DISPLAY_COMMENT) {
|
||||
pageClicked(-1, parseInt($('#doc_id').val()));
|
||||
}
|
||||
|
||||
$("div.wiki-bottom").after("<div class='wiki-bottom-left'>上一篇: <a href='/docs/{{.PrevPath}}' rel='prev'>{{.PrevName}}</a><br />下一篇: <a href='/docs/{{.NextPath}}' rel='next'>{{.NextName}}</a><br /></div>");
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
{{.Scripts}}
|
||||
|
5
views/document/test.tpl
Normal file
5
views/document/test.tpl
Normal file
@ -0,0 +1,5 @@
|
||||
<div class=\"whole-article-wrap\">
|
||||
<p class=\"line\">师傅大哥水电费788778778</p>
|
||||
<div class=\"wiki-bottom-left\">作者:admin 创建时间:2024-04-21 10:06<br />最后编辑:admin 更新时间:2024-04-26 23:31<br /></div>
|
||||
<div class=\"wiki-bottom\">作者:admin 创建时间:2024-04-21 10:06<br />最后编辑:admin 更新时间:2024-04-26 23:31<br /></div>
|
||||
</div>
|
38
win下编译.md
38
win下编译.md
@ -1,38 +0,0 @@
|
||||
win下
|
||||
修改conf里
|
||||
注释掉mysql
|
||||
取消sqlite注释
|
||||
拷贝一个sqlite数据库到database文件夹里,更名为mindoc.db
|
||||
cmd进入mindoc文件夹
|
||||
因为用sqlite需要cgo,go env -w CGO_ENABLED=1
|
||||
https://blog.csdn.net/qq_43625649/article/details/134488353
|
||||
|
||||
D:\gowork>cd src
|
||||
|
||||
D:\gowork\src>cd github.com
|
||||
|
||||
D:\gowork\src\github.com>cd mindoc
|
||||
|
||||
D:\gowork\src\github.com\mindoc>bee run
|
||||
______
|
||||
| ___ \
|
||||
| |_/ / ___ ___
|
||||
| ___ \ / _ \ / _ \
|
||||
| |_/ /| __/| __/
|
||||
\____/ \___| \___| v2.0.4
|
||||
2024/04/19 21:21:29 WARN ▶ 0001 Running application outside of GOPATH
|
||||
2024/04/19 21:21:29 INFO ▶ 0002 Using 'mindoc' as 'appname'
|
||||
2024/04/19 21:21:29 INFO ▶ 0003 Initializing watcher...
|
||||
github.com/mattn/go-sqlite3
|
||||
github.com/mindoc-org/mindoc
|
||||
2024/04/19 21:22:04 SUCCESS ▶ 0004 Built Successfully!
|
||||
2024/04/19 21:22:04 INFO ▶ 0005 Restarting 'mindoc.exe'...
|
||||
2024/04/19 21:22:04 SUCCESS ▶ 0006 './mindoc.exe' is running...
|
||||
2024/04/19 21:22:05.230 [I] [command.go:38] 正在初始化数据库配置.
|
||||
2024/04/19 21:22:05.260 [I] [command.go:115] 数据库初始化完成.
|
||||
MinDoc version =>
|
||||
build time =>
|
||||
start directory => D:\gowork\src\github.com\mindoc\mindoc.exe
|
||||
|
||||
2024/04/19 21:22:05.453 [I] [server.go:281] http server Running on http://:8181
|
||||
|
Loading…
Reference in New Issue
Block a user