Compare commits
No commits in common. 'bef4f433fcc22cfe0ad840d3b53500164753fd1a' and '77a984170cf7532753b51e99334853c41085381e' have entirely different histories.
bef4f433fc
...
77a984170c
@ -1,37 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from .models import Page
|
||||
|
||||
content_path = Path(__file__).resolve().parent / "default_content"
|
||||
|
||||
|
||||
def import_pages(force, pages):
|
||||
for file in content_path.iterdir():
|
||||
if pages and file.stem not in pages:
|
||||
continue
|
||||
|
||||
slug = file.stem
|
||||
p, created = Page.objects.get_or_create(url=slug)
|
||||
if not created and not force:
|
||||
continue
|
||||
|
||||
soup = BeautifulSoup(file.read_text(), "html.parser")
|
||||
|
||||
if soup.title:
|
||||
p.title = soup.title.string
|
||||
soup.title.decompose()
|
||||
else:
|
||||
p.title = slug.title()
|
||||
|
||||
if visible := soup.find("meta", attrs={"name": "visible"}):
|
||||
p.visible = "content" not in visible.attrs or visible.attrs[
|
||||
"content"
|
||||
].lower() in ("1", "true", "yes")
|
||||
visible.decompose()
|
||||
|
||||
p.content = str(soup).strip()
|
||||
p.save()
|
||||
|
||||
yield p
|
Loading…
Reference in New Issue