更新评论模块
parent
9c0d18a6d0
commit
f4597906c0
|
@ -89,7 +89,9 @@ content目录下的一级目录代表一个分类,如果一级目录下有子
|
||||||
## 更新日志
|
## 更新日志
|
||||||
|
|
||||||
### V3.2
|
### V3.2
|
||||||
|
* 加入搜索功能
|
||||||
* 加入Tag搜索和展示
|
* 加入Tag搜索和展示
|
||||||
|
* 加入Gitalk评论支持(可选)
|
||||||
|
|
||||||
### V3.1
|
### V3.1
|
||||||
* 去掉标题的.MD后缀
|
* 去掉标题的.MD后缀
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
"webHookSecret": "jixieshi",
|
"webHookSecret": "jixieshi",
|
||||||
"categoryDisplayQuantity": 6,
|
"categoryDisplayQuantity": 6,
|
||||||
"utterancesRepo": "jixishi/blog_docs",
|
"utterancesRepo": "jixishi/blog_docs",
|
||||||
|
"gitalk_clientID": "2c40e5de269c2c61dc91",
|
||||||
|
"gitalk_clientSecret": "d976941995470662ec039028fe37c0466bd27027",
|
||||||
|
"gitalk_owner": "jixishi",
|
||||||
|
"gitalk_repo": "",
|
||||||
|
"gitalk_repo": "",
|
||||||
"timeLayout": "2006.01.02 15:04",
|
"timeLayout": "2006.01.02 15:04",
|
||||||
"siteName": "JiXieShi's Blog",
|
"siteName": "JiXieShi's Blog",
|
||||||
"htmlKeywords": "forest blog,Golang,ARM,BE6,前端,硬件",
|
"htmlKeywords": "forest blog,Golang,ARM,BE6,前端,硬件",
|
||||||
|
@ -16,4 +21,4 @@
|
||||||
"themeColor": "#2196f3",
|
"themeColor": "#2196f3",
|
||||||
"dashboard": "/adminjxs",
|
"dashboard": "/adminjxs",
|
||||||
"themeOption": ["#673ab7","#f44336","#9c27b0","#2196f3","#607d8b","#795548"]
|
"themeOption": ["#673ab7","#f44336","#9c27b0","#2196f3","#607d8b","#795548"]
|
||||||
}
|
}
|
|
@ -17,6 +17,14 @@ type userConfig struct {
|
||||||
|
|
||||||
UtterancesRepo string `json:"utterancesRepo"`
|
UtterancesRepo string `json:"utterancesRepo"`
|
||||||
|
|
||||||
|
Gitalk_ClientID string `json:"gitalk_clientID"`
|
||||||
|
|
||||||
|
Gitalk_ClientSecret string `json:"gitalk_clientSecret"`
|
||||||
|
|
||||||
|
Gitalk_Repo string `json:"gitalk_repo"`
|
||||||
|
|
||||||
|
Gitalk_Owner string `json:"gitalk_owner"`
|
||||||
|
|
||||||
PageSize int `json:"pageSize"`
|
PageSize int `json:"pageSize"`
|
||||||
|
|
||||||
DescriptionLen int `json:"descriptionLen"`
|
DescriptionLen int `json:"descriptionLen"`
|
||||||
|
|
|
@ -15,7 +15,7 @@ func Article(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
path := models.ArticleShortUrlMap[key]
|
path := models.ArticleShortUrlMap[key]
|
||||||
|
|
||||||
articleDetail, err := models.ReadArticleDetail(path)
|
articleDetail, err := models.ReadArticleDetail(path, key)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
articleTemplate.WriteError(w, err)
|
articleTemplate.WriteError(w, err)
|
||||||
|
|
|
@ -15,7 +15,7 @@ func ExtraNav(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.Form.Get("name")
|
name := r.Form.Get("name")
|
||||||
for _, nav := range models.Navigation {
|
for _, nav := range models.Navigation {
|
||||||
if nav.Title == name {
|
if nav.Title == name {
|
||||||
articleDetail, err := models.ReadArticleDetail(nav.Path)
|
articleDetail, err := models.ReadArticleDetail(nav.Path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
extraNavTemplate.WriteError(w, err)
|
extraNavTemplate.WriteError(w, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,22 +139,22 @@ func RecursiveReadArticles(dir string) (Articles, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadArticle(path string) (Article, error) {
|
func ReadArticle(path string) (Article, error) {
|
||||||
article, _, err := readMarkdown(path)
|
article, _, err := readMarkdown(path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return article, err
|
return article, err
|
||||||
}
|
}
|
||||||
return article, nil
|
return article, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadArticleDetail(path string) (ArticleDetail, error) {
|
func ReadArticleDetail(path, key string) (ArticleDetail, error) {
|
||||||
_, articleDetail, err := readMarkdown(path)
|
_, articleDetail, err := readMarkdown(path, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return articleDetail, err
|
return articleDetail, err
|
||||||
}
|
}
|
||||||
return articleDetail, nil
|
return articleDetail, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readMarkdown(path string) (Article, ArticleDetail, error) {
|
func readMarkdown(path, key string) (Article, ArticleDetail, error) {
|
||||||
var article Article
|
var article Article
|
||||||
var articleDetail ArticleDetail
|
var articleDetail ArticleDetail
|
||||||
mdFile, err := os.Stat(path)
|
mdFile, err := os.Stat(path)
|
||||||
|
@ -171,7 +171,9 @@ func readMarkdown(path string) (Article, ArticleDetail, error) {
|
||||||
return article, articleDetail, err
|
return article, articleDetail, err
|
||||||
}
|
}
|
||||||
markdown = bytes.TrimSpace(markdown)
|
markdown = bytes.TrimSpace(markdown)
|
||||||
|
if key != "" {
|
||||||
|
article.ShortUrl = key
|
||||||
|
}
|
||||||
article.Path = path
|
article.Path = path
|
||||||
article.Category = GetCategoryName(path)
|
article.Category = GetCategoryName(path)
|
||||||
article.Title = strings.TrimSuffix(strings.ToUpper(mdFile.Name()), ".MD")
|
article.Title = strings.TrimSuffix(strings.ToUpper(mdFile.Name()), ".MD")
|
||||||
|
|
|
@ -76,12 +76,12 @@ func readHtmlTemplate(htmlFileName []string, viewDir string) ([]TemplatePointer,
|
||||||
|
|
||||||
head := viewDir + "/layouts/head.html"
|
head := viewDir + "/layouts/head.html"
|
||||||
footer := viewDir + "/layouts/footer.html"
|
footer := viewDir + "/layouts/footer.html"
|
||||||
|
reviews := viewDir + "/layouts/reviews.html"
|
||||||
for _, name := range htmlFileName {
|
for _, name := range htmlFileName {
|
||||||
|
|
||||||
tp, err := template.New(name+".html").
|
tp, err := template.New(name+".html").
|
||||||
Funcs(template.FuncMap{"SpreadDigit": SpreadDigit}).
|
Funcs(template.FuncMap{"SpreadDigit": SpreadDigit}).
|
||||||
ParseFiles(viewDir+"/"+name+".html", head, footer)
|
ParseFiles(viewDir+"/"+name+".html", head, footer, reviews)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return htmlTemplate, err
|
return htmlTemplate, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,5 @@
|
||||||
document.getElementById('article').innerHTML = marked({{ .Data.Body }});
|
document.getElementById('article').innerHTML = marked({{ .Data.Body }});
|
||||||
</script>
|
</script>
|
||||||
<script src="/public/js/prism.js"></script>
|
<script src="/public/js/prism.js"></script>
|
||||||
{{if ne .Config.UtterancesRepo ""}}
|
{{template "reviews" .}}
|
||||||
<script src="https://utteranc.es/client.js" repo="{{ .Config.UtterancesRepo }}" issue-term="[{{ .Data.Title }}]"
|
|
||||||
theme="github-light" crossorigin="anonymous" async>
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
||||||
{{template "footer" .}}
|
{{template "footer" .}}
|
|
@ -0,0 +1,26 @@
|
||||||
|
{{define "reviews"}}
|
||||||
|
{{if ne .Config.UtterancesRepo ""}}
|
||||||
|
<script src="https://utteranc.es/client.js" repo="{{ .Config.UtterancesRepo }}" issue-term="[{{ .Data.Title }}]"
|
||||||
|
theme="github-light" crossorigin="anonymous" async>
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{if ne .Config.Gitalk_Repo ""}}
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
|
||||||
|
<div id="gitalk-container"></div>
|
||||||
|
<script>
|
||||||
|
var gitalk = new Gitalk({
|
||||||
|
title: "{{ .Data.Title }}",
|
||||||
|
clientID: "{{ .Config.Gitalk_ClientID }}",
|
||||||
|
clientSecret: "{{ .Config.Gitalk_ClientSecret }}",
|
||||||
|
repo: "{{ .Config.Gitalk_Repo }}",
|
||||||
|
owner: "{{ .Config.Gitalk_Owner }}",
|
||||||
|
admin: "[{{ .Config.Gitalk_Owner }}]",
|
||||||
|
id: "{{ .Data.ShortUrl }}", // Ensure uniqueness and length less than 50
|
||||||
|
distractionFreeMode: false // Facebook-like distraction free mode
|
||||||
|
})
|
||||||
|
gitalk.render('gitalk-container')
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
|
{{ end }}
|
|
@ -369,19 +369,20 @@ hr:after{
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
.search-box{
|
.search-box{
|
||||||
height: 40px;
|
height: 36px;
|
||||||
display: flex;
|
display: flex;
|
||||||
border-radius: 2px;
|
border-radius: 16px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
border: 1px solid #673ab7;
|
border: 1px solid #673ab7;
|
||||||
border: 1px solid var(--primary,#673ab7);
|
border: 2px solid var(--primary,#673ab7);
|
||||||
width: 320px;
|
width: 320px;
|
||||||
}
|
}
|
||||||
.search-input{
|
.search-input{
|
||||||
text-align: center;
|
text-align: center;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
border: none;
|
border: none;
|
||||||
|
border-radius: 16px;border-radius: 16px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
}
|
}
|
||||||
|
|
4
配置说明.md
4
配置说明.md
|
@ -8,6 +8,10 @@
|
||||||
- "webHookSecret": 博客文章更新勾子的密钥,这里要和你在仓库设置的密钥一样,
|
- "webHookSecret": 博客文章更新勾子的密钥,这里要和你在仓库设置的密钥一样,
|
||||||
- "categoryDisplayQuantity": 在分类页面下,每个分类下最多展示多少篇文章,
|
- "categoryDisplayQuantity": 在分类页面下,每个分类下最多展示多少篇文章,
|
||||||
- "utterancesRepo": 是否开启utterances评论,留空没有评论,否则填写评论存储的仓库name/repo,
|
- "utterancesRepo": 是否开启utterances评论,留空没有评论,否则填写评论存储的仓库name/repo,
|
||||||
|
- "gitalk_repo": 是否开启Gitalks评论,留空没有评论,否则填写评论存储的仓库repo,
|
||||||
|
- "gitalk_clientID": 应用id,
|
||||||
|
- "gitalk_clientSecret": 应用授权密钥,
|
||||||
|
- "gitalk_owner": 仓库所有者,
|
||||||
- "timeLayout": 解析时间的格式,保持和你文章里面的date字段一样,除非了解Golang的时间解析,否则不要修改,
|
- "timeLayout": 解析时间的格式,保持和你文章里面的date字段一样,除非了解Golang的时间解析,否则不要修改,
|
||||||
- "siteName": 网站的名字,
|
- "siteName": 网站的名字,
|
||||||
- "documentGitUrl": 你文章的git地址,应用会把文章克隆在当前目录下,必须公开并且以.git结尾,
|
- "documentGitUrl": 你文章的git地址,应用会把文章克隆在当前目录下,必须公开并且以.git结尾,
|
||||||
|
|
Loading…
Reference in New Issue