mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-11 15:51:19 +00:00
Update settings.BASE_DIR usage sites to use pathlib
This commit is contained in:
parent
b9d016b799
commit
4a72519c71
3 changed files with 10 additions and 15 deletions
hc/front
|
@ -14,7 +14,7 @@ class Command(BaseCommand):
|
|||
help = "Renders Markdown to HTML"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
con = sqlite3.connect(os.path.join(settings.BASE_DIR, "search.db"))
|
||||
con = sqlite3.connect(settings.BASE_DIR / "search.db")
|
||||
cur = con.cursor()
|
||||
cur.execute("DROP TABLE IF EXISTS docs")
|
||||
cur.execute(
|
||||
|
|
|
@ -33,21 +33,16 @@ class Command(BaseCommand):
|
|||
}
|
||||
|
||||
def process_directory(path):
|
||||
for doc in os.listdir(path):
|
||||
if not doc.endswith(".md"):
|
||||
continue
|
||||
for src_path in path.glob("*.md"):
|
||||
print(f"Rendering {src_path.name}")
|
||||
|
||||
print("Rendering %s" % doc)
|
||||
|
||||
src_path = os.path.join(path, doc)
|
||||
dst_path = os.path.join(path, doc[:-3] + ".html-fragment")
|
||||
|
||||
text = open(src_path, "r", encoding="utf-8").read()
|
||||
text = src_path.open("r", encoding="utf-8").read()
|
||||
html = markdown.markdown(
|
||||
text, extensions=extensions, extension_configs=extension_configs
|
||||
)
|
||||
|
||||
with open(dst_path, "w", encoding="utf-8") as f:
|
||||
dst_path = src_path.with_suffix(".html-fragment")
|
||||
with dst_path.open("w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
|
||||
process_directory(os.path.join(settings.BASE_DIR, "templates/docs"))
|
||||
process_directory(settings.BASE_DIR / "templates/docs")
|
||||
|
|
|
@ -423,11 +423,11 @@ def serve_doc(request, doc="introduction"):
|
|||
if not re.match(r"^[0-9a-z_]+$", doc):
|
||||
raise Http404("not found")
|
||||
|
||||
path = os.path.join(settings.BASE_DIR, "templates/docs", doc + ".html-fragment")
|
||||
if not os.path.exists(path):
|
||||
path = settings.BASE_DIR / f"templates/docs/{doc}.html-fragment"
|
||||
if not path.exists():
|
||||
raise Http404("not found")
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with path.open("r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
content = _replace_placeholders(doc, content)
|
||||
|
|
Loading…
Add table
Reference in a new issue