This commit is contained in:
lianglianglee 2023-11-07 11:05:36 +08:00
parent 65baf21a64
commit 29ed9f44eb
4 changed files with 11 additions and 3 deletions

View File

@ -3,3 +3,4 @@ server:
dir: dir:
root: \Gitlab\note root: \Gitlab\note
main: PDF main: PDF
message: <a target="_blank" href='https://www.aliyun.com/minisite/goods?userCode=lc4iupk4'>阿里云2C2G3M 99元/年,老用户也可以哦<a/><hr />

View File

@ -3,6 +3,7 @@ package controller
import ( import (
"gin-demo/response" "gin-demo/response"
"gin-demo/util" "gin-demo/util"
"html/template"
"os" "os"
"strings" "strings"
@ -31,6 +32,10 @@ func (c CategoryController) Show(ctx *gin.Context) {
} }
} }
rootDir := viper.GetString("dir.root") rootDir := viper.GetString("dir.root")
message := template.HTML("")
if "" != viper.GetString("message") {
message = template.HTML(viper.GetString("message"))
}
path := rootDir + urlPath path := rootDir + urlPath
pathInfo, err := os.Stat(path) pathInfo, err := os.Stat(path)
listResult := util.GetFileList(path) listResult := util.GetFileList(path)
@ -40,18 +45,18 @@ func (c CategoryController) Show(ctx *gin.Context) {
} }
if pathInfo.IsDir() { if pathInfo.IsDir() {
if urlPath == "/" { if urlPath == "/" {
path = path + viper.GetString("dir.main") path = path + viper.GetString("dir.main")
} }
htmlContext := util.GetDirStr(path) htmlContext := util.GetDirStr(path)
//fmt.Println(htmlContext) //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") { } else if strings.HasSuffix(pathInfo.Name(), ".md") {
// 后缀判断 // 后缀判断
htmlContext := util.GetMdStr(path) htmlContext := util.GetMdStr(path)
//fmt.Println(htmlContext) //fmt.Println(htmlContext)
title := pathInfo.Name() title := pathInfo.Name()
title = strings.ReplaceAll(title, ".md", "") 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 { } else {
ctx.Header("Cache-Control", "public,s-maxage=300,max-age=31536000") ctx.Header("Cache-Control", "public,s-maxage=300,max-age=31536000")
ctx.File(path) ctx.File(path)

View File

@ -28,6 +28,7 @@ func InitConfig() {
viper.SetConfigType("yml") viper.SetConfigType("yml")
viper.AddConfigPath(workDir + "/config") viper.AddConfigPath(workDir + "/config")
err := viper.ReadInConfig() err := viper.ReadInConfig()
viper.WatchConfig()
if err != nil { if err != nil {
panic("") panic("")
} }

View File

@ -66,6 +66,7 @@
overflow-x: auto; overflow-x: auto;
overflow-y: hidden;"> overflow-y: hidden;">
<div class="book-post"> <div class="book-post">
<div align="center">{{.message}}</div>
<p id="tip" align="center"></p> <p id="tip" align="center"></p>
<p class="title">{{.title}}</p> <p class="title">{{.title}}</p>
<div>{{ .htmlContext }}</div> <div>{{ .htmlContext }}</div>