@@ -67,6 +67,7 @@ type ArticleConfig struct {
6767 Top bool
6868 Type string
6969 Hide bool
70+ Toc bool
7071 Image string
7172 Subtitle string
7273 Config map [string ]interface {}
@@ -129,11 +130,14 @@ func renderHookLazyLoadImage(w io.Writer, node ast.Node, entering bool) (ast.Wal
129130 return ast .GoToNext , false
130131}
131132
132- func ParseMarkdown (markdown string ) template.HTML {
133+ func ParseMarkdown (markdown string , toc bool ) template.HTML {
133134 extensions := parser .CommonExtensions | parser .Footnotes
134135 parser := parser .NewWithExtensions (extensions )
135136
136137 htmlFlags := html .CommonFlags
138+ if toc {
139+ htmlFlags |= html .TOC
140+ }
137141 opts := html.RendererOptions {Flags : htmlFlags , RenderNodeHook : renderHookLazyLoadImage }
138142 renderer := html .NewRenderer (opts )
139143
@@ -226,10 +230,10 @@ func ParseArticleConfig(markdownPath string) (config *ArticleConfig, content str
226230 // Parse preview splited by MORE_SPLIT
227231 previewAry := strings .SplitN (content , MORE_SPLIT , 2 )
228232 if len (config .Preview ) <= 0 && len (previewAry ) > 1 {
229- config .Preview = ParseMarkdown (previewAry [0 ])
233+ config .Preview = ParseMarkdown (previewAry [0 ], false )
230234 content = strings .Replace (content , MORE_SPLIT , "" , 1 )
231235 } else {
232- config .Preview = ParseMarkdown (string (config .Preview ))
236+ config .Preview = ParseMarkdown (string (config .Preview ), false )
233237 }
234238 return config , content
235239}
@@ -250,7 +254,7 @@ func ParseArticle(markdownPath string) *Article {
250254 article .Preview = config .Preview
251255 article .Config = config .Config
252256 article .Markdown = content
253- article .Content = ParseMarkdown (content )
257+ article .Content = ParseMarkdown (content , config . Toc )
254258 if config .Date != "" {
255259 article .Time = ParseDate (config .Date )
256260 article .Date = article .Time .Unix ()
0 commit comments