Extract TOC
This commit is contained in:
parent
3a32e32fca
commit
22731310ba
2 changed files with 10 additions and 1 deletions
|
@ -20,6 +20,7 @@ class Page(models.Model):
|
|||
|
||||
raw_content = models.TextField()
|
||||
content = models.TextField()
|
||||
toc = models.JSONField()
|
||||
slug = models.CharField(max_length=128, unique=True, db_index=True, default=None, null=True)
|
||||
|
||||
tags = models.ManyToManyField(Tag)
|
||||
|
@ -28,9 +29,16 @@ class Page(models.Model):
|
|||
def from_yaml(cls, **data):
|
||||
tags = data.pop("tags", None)
|
||||
|
||||
md = markdown.Markdown(extensions=["toc"])
|
||||
|
||||
content = data.pop("content")
|
||||
data["raw_content"] = content
|
||||
data["content"] = markdown.markdown(content)
|
||||
|
||||
data["content"] = md.convert(content)
|
||||
data["toc"] = {
|
||||
"html": md.toc,
|
||||
"tokens": md.toc_tokens
|
||||
}
|
||||
|
||||
instance = cls.objects.create(**data)
|
||||
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
<title>{{ page.title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
{{ page.toc.html|safe }}
|
||||
{{ content }}
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue