Skip to content

Commit

Permalink
Update build_database.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding4Hours authored Jul 13, 2024
1 parent 4bfc875 commit 01e1a8f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions build_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ def build_database(repo_path):
table = db.table("til", pk="path")
for filepath in root.glob("*/*.md"):
with filepath.open() as fp:
title = fp.readline().lstrip("#").strip()
body = fp.read().strip()
# Read all lines of the file
lines = fp.readlines()
# Get the fifth line as the title
if len(lines) >= 5:
title = lines[4].lstrip("#").strip()
else:
title = ""
# Read the rest of the file as the body
body = "".join(lines[5:]).strip()
path = str(filepath.relative_to(root))
url = f"https://coding4hours.github.io/Til/" + urllib.parse.quote(path.replace(" ", "-").replace(".md", ""))
record = {
Expand Down

0 comments on commit 01e1a8f

Please sign in to comment.