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()
|
raw_content = models.TextField()
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
|
toc = models.JSONField()
|
||||||
slug = models.CharField(max_length=128, unique=True, db_index=True, default=None, null=True)
|
slug = models.CharField(max_length=128, unique=True, db_index=True, default=None, null=True)
|
||||||
|
|
||||||
tags = models.ManyToManyField(Tag)
|
tags = models.ManyToManyField(Tag)
|
||||||
|
@ -28,9 +29,16 @@ class Page(models.Model):
|
||||||
def from_yaml(cls, **data):
|
def from_yaml(cls, **data):
|
||||||
tags = data.pop("tags", None)
|
tags = data.pop("tags", None)
|
||||||
|
|
||||||
|
md = markdown.Markdown(extensions=["toc"])
|
||||||
|
|
||||||
content = data.pop("content")
|
content = data.pop("content")
|
||||||
data["raw_content"] = 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)
|
instance = cls.objects.create(**data)
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
<title>{{ page.title }}</title>
|
<title>{{ page.title }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
{{ page.toc.html|safe }}
|
||||||
{{ content }}
|
{{ content }}
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue