message
This commit is contained in:
parent
65baf21a64
commit
29ed9f44eb
|
@ -3,3 +3,4 @@ server:
|
|||
dir:
|
||||
root: \Gitlab\note
|
||||
main: PDF
|
||||
message: <a target="_blank" href='https://www.aliyun.com/minisite/goods?userCode=lc4iupk4'>阿里云2C2G3M 99元/年,老用户也可以哦<a/><hr />
|
|
@ -3,6 +3,7 @@ package controller
|
|||
import (
|
||||
"gin-demo/response"
|
||||
"gin-demo/util"
|
||||
"html/template"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -31,6 +32,10 @@ func (c CategoryController) Show(ctx *gin.Context) {
|
|||
}
|
||||
}
|
||||
rootDir := viper.GetString("dir.root")
|
||||
message := template.HTML("")
|
||||
if "" != viper.GetString("message") {
|
||||
message = template.HTML(viper.GetString("message"))
|
||||
}
|
||||
path := rootDir + urlPath
|
||||
pathInfo, err := os.Stat(path)
|
||||
listResult := util.GetFileList(path)
|
||||
|
@ -40,18 +45,18 @@ func (c CategoryController) Show(ctx *gin.Context) {
|
|||
}
|
||||
if pathInfo.IsDir() {
|
||||
if urlPath == "/" {
|
||||
path = path + viper.GetString("dir.main")
|
||||
path = path + viper.GetString("dir.main")
|
||||
}
|
||||
htmlContext := util.GetDirStr(path)
|
||||
//fmt.Println(htmlContext)
|
||||
response.Success(ctx, gin.H{"title": pathInfo.Name(), "htmlContext": htmlContext, "list": listResult})
|
||||
response.Success(ctx, gin.H{"title": pathInfo.Name(), "htmlContext": htmlContext, "list": listResult, "message": message})
|
||||
} else if strings.HasSuffix(pathInfo.Name(), ".md") {
|
||||
// 后缀判断
|
||||
htmlContext := util.GetMdStr(path)
|
||||
//fmt.Println(htmlContext)
|
||||
title := pathInfo.Name()
|
||||
title = strings.ReplaceAll(title, ".md", "")
|
||||
response.Success(ctx, gin.H{"title": title, "htmlContext": htmlContext, "list": listResult})
|
||||
response.Success(ctx, gin.H{"title": title, "htmlContext": htmlContext, "list": listResult, "message": message})
|
||||
} else {
|
||||
ctx.Header("Cache-Control", "public,s-maxage=300,max-age=31536000")
|
||||
ctx.File(path)
|
||||
|
|
1
main.go
1
main.go
|
@ -28,6 +28,7 @@ func InitConfig() {
|
|||
viper.SetConfigType("yml")
|
||||
viper.AddConfigPath(workDir + "/config")
|
||||
err := viper.ReadInConfig()
|
||||
viper.WatchConfig()
|
||||
if err != nil {
|
||||
panic("")
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
overflow-x: auto;
|
||||
overflow-y: hidden;">
|
||||
<div class="book-post">
|
||||
<div align="center">{{.message}}</div>
|
||||
<p id="tip" align="center"></p>
|
||||
<p class="title">{{.title}}</p>
|
||||
<div>{{ .htmlContext }}</div>
|
||||
|
|
Loading…
Reference in New Issue