Skip to content

Commit 31b1cd8

Browse files
committed
🎨 ToC
1 parent 393f8cc commit 31b1cd8

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

controller/activityctl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
// Package controller is the "controller" layer.
1718
package controller
1819

1920
import (

controller/articlectl.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strconv"
2424
"strings"
2525

26+
"github.com/PuerkitoBio/goquery"
2627
"github.com/b3log/pipe/model"
2728
"github.com/b3log/pipe/service"
2829
"github.com/b3log/pipe/util"
@@ -219,7 +220,8 @@ func showArticleAction(c *gin.Context) {
219220
dataModel["RelevantArticles"] = articles
220221
fillPreviousArticle(c, article, &dataModel)
221222
fillNextArticle(c, article, &dataModel)
222-
dataModel["ToC"] = "todo"
223+
logger.Info(mdResult.ContentHTML)
224+
dataModel["ToC"] = ToC(mdResult.ContentHTML)
223225
c.HTML(http.StatusOK, getTheme(c)+"/article.html", dataModel)
224226

225227
service.Article.IncArticleViewCount(article)
@@ -262,3 +264,23 @@ func fillNextArticle(c *gin.Context, article *model.Article, dataModel *DataMode
262264
}
263265
(*dataModel)["NextArticle"] = nextArticle
264266
}
267+
268+
func ToC(content string) string {
269+
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(content))
270+
elements := doc.Find("h1, h2, h3, h4, h5")
271+
if nil == elements || 3 > elements.Length() {
272+
return ""
273+
}
274+
275+
ret := "<ul class=\"article-toc\">"
276+
elements.Each(func(i int, ele *goquery.Selection) {
277+
// ele.Nodes[0]
278+
279+
logger.Infof("%+v", ele)
280+
281+
})
282+
283+
_ = ret
284+
285+
return ""
286+
}

model/archive.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
// Package model is the "model" layer which defines entity structures with ORM.
1718
package model
1819

1920
// Archive model.

model/article.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
// Package model is the "model" layer which defines entity structures with ORM.
1817
package model
1918

2019
// Article model.

0 commit comments

Comments
 (0)