diff --git a/README.md b/README.md index 32acbc4..ec069f7 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,9 @@ content目录下的一级目录代表一个分类,如果一级目录下有子 ## 更新日志 ### V3.2 +* 加入搜索功能 * 加入Tag搜索和展示 +* 加入Gitalk评论支持(可选) ### V3.1 * 去掉标题的.MD后缀 diff --git a/config.json b/config.json index 60677db..cab3cc8 100644 --- a/config.json +++ b/config.json @@ -7,6 +7,11 @@ "webHookSecret": "jixieshi", "categoryDisplayQuantity": 6, "utterancesRepo": "jixishi/blog_docs", + "gitalk_clientID": "2c40e5de269c2c61dc91", + "gitalk_clientSecret": "d976941995470662ec039028fe37c0466bd27027", + "gitalk_owner": "jixishi", + "gitalk_repo": "", + "gitalk_repo": "", "timeLayout": "2006.01.02 15:04", "siteName": "JiXieShi's Blog", "htmlKeywords": "forest blog,Golang,ARM,BE6,前端,硬件", @@ -16,4 +21,4 @@ "themeColor": "#2196f3", "dashboard": "/adminjxs", "themeOption": ["#673ab7","#f44336","#9c27b0","#2196f3","#607d8b","#795548"] -} +} \ No newline at end of file diff --git a/config/user.go b/config/user.go index 9bd2334..6f0d511 100644 --- a/config/user.go +++ b/config/user.go @@ -17,6 +17,14 @@ type userConfig struct { 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"` DescriptionLen int `json:"descriptionLen"` diff --git a/controller/article.go b/controller/article.go index 2433eb8..e02e7d8 100644 --- a/controller/article.go +++ b/controller/article.go @@ -15,7 +15,7 @@ func Article(w http.ResponseWriter, r *http.Request) { path := models.ArticleShortUrlMap[key] - articleDetail, err := models.ReadArticleDetail(path) + articleDetail, err := models.ReadArticleDetail(path, key) if err != nil { articleTemplate.WriteError(w, err) diff --git a/controller/extraNav.go b/controller/extraNav.go index fd2e463..830c718 100644 --- a/controller/extraNav.go +++ b/controller/extraNav.go @@ -15,7 +15,7 @@ func ExtraNav(w http.ResponseWriter, r *http.Request) { name := r.Form.Get("name") for _, nav := range models.Navigation { if nav.Title == name { - articleDetail, err := models.ReadArticleDetail(nav.Path) + articleDetail, err := models.ReadArticleDetail(nav.Path, "") if err != nil { extraNavTemplate.WriteError(w, err) } diff --git a/models/articles.go b/models/articles.go index 964daf2..7af9fc5 100644 --- a/models/articles.go +++ b/models/articles.go @@ -139,22 +139,22 @@ func RecursiveReadArticles(dir string) (Articles, error) { } func ReadArticle(path string) (Article, error) { - article, _, err := readMarkdown(path) + article, _, err := readMarkdown(path, "") if err != nil { return article, err } return article, nil } -func ReadArticleDetail(path string) (ArticleDetail, error) { - _, articleDetail, err := readMarkdown(path) +func ReadArticleDetail(path, key string) (ArticleDetail, error) { + _, articleDetail, err := readMarkdown(path, key) if err != nil { return articleDetail, err } return articleDetail, nil } -func readMarkdown(path string) (Article, ArticleDetail, error) { +func readMarkdown(path, key string) (Article, ArticleDetail, error) { var article Article var articleDetail ArticleDetail mdFile, err := os.Stat(path) @@ -171,7 +171,9 @@ func readMarkdown(path string) (Article, ArticleDetail, error) { return article, articleDetail, err } markdown = bytes.TrimSpace(markdown) - + if key != "" { + article.ShortUrl = key + } article.Path = path article.Category = GetCategoryName(path) article.Title = strings.TrimSuffix(strings.ToUpper(mdFile.Name()), ".MD") diff --git a/models/html_template.go b/models/html_template.go index d647be4..ce773b5 100644 --- a/models/html_template.go +++ b/models/html_template.go @@ -76,12 +76,12 @@ func readHtmlTemplate(htmlFileName []string, viewDir string) ([]TemplatePointer, head := viewDir + "/layouts/head.html" footer := viewDir + "/layouts/footer.html" - + reviews := viewDir + "/layouts/reviews.html" for _, name := range htmlFileName { tp, err := template.New(name+".html"). Funcs(template.FuncMap{"SpreadDigit": SpreadDigit}). - ParseFiles(viewDir+"/"+name+".html", head, footer) + ParseFiles(viewDir+"/"+name+".html", head, footer, reviews) if err != nil { return htmlTemplate, err } diff --git a/themes/blog/article.html b/themes/blog/article.html index 0081c66..bfa4ed1 100644 --- a/themes/blog/article.html +++ b/themes/blog/article.html @@ -47,9 +47,5 @@ document.getElementById('article').innerHTML = marked({{ .Data.Body }}); -{{if ne .Config.UtterancesRepo ""}} - -{{end}} +{{template "reviews" .}} {{template "footer" .}} \ No newline at end of file diff --git a/themes/blog/layouts/reviews.html b/themes/blog/layouts/reviews.html new file mode 100644 index 0000000..a04740f --- /dev/null +++ b/themes/blog/layouts/reviews.html @@ -0,0 +1,26 @@ +{{define "reviews"}} +{{if ne .Config.UtterancesRepo ""}} + +{{end}} + +{{if ne .Config.Gitalk_Repo ""}} + + +
+ +{{end}} +{{ end }} \ No newline at end of file diff --git a/themes/blog/public/css/app.css b/themes/blog/public/css/app.css index 141f226..87d7fc7 100644 --- a/themes/blog/public/css/app.css +++ b/themes/blog/public/css/app.css @@ -369,19 +369,20 @@ hr:after{ align-items: center; } .search-box{ - height: 40px; + height: 36px; display: flex; - border-radius: 2px; + border-radius: 16px; align-items: center; justify-content: space-between; border: 1px solid #673ab7; - border: 1px solid var(--primary,#673ab7); + border: 2px solid var(--primary,#673ab7); width: 320px; } .search-input{ text-align: center; flex: 1; border: none; + border-radius: 16px;border-radius: 16px; height: 30px; padding: 0 10px; } diff --git a/配置说明.md b/配置说明.md index 1bebf04..2b92886 100644 --- a/配置说明.md +++ b/配置说明.md @@ -8,6 +8,10 @@ - "webHookSecret": 博客文章更新勾子的密钥,这里要和你在仓库设置的密钥一样, - "categoryDisplayQuantity": 在分类页面下,每个分类下最多展示多少篇文章, - "utterancesRepo": 是否开启utterances评论,留空没有评论,否则填写评论存储的仓库name/repo, +- "gitalk_repo": 是否开启Gitalks评论,留空没有评论,否则填写评论存储的仓库repo, +- "gitalk_clientID": 应用id, +- "gitalk_clientSecret": 应用授权密钥, +- "gitalk_owner": 仓库所有者, - "timeLayout": 解析时间的格式,保持和你文章里面的date字段一样,除非了解Golang的时间解析,否则不要修改, - "siteName": 网站的名字, - "documentGitUrl": 你文章的git地址,应用会把文章克隆在当前目录下,必须公开并且以.git结尾,