add header parsing
This commit is contained in:
parent
9cb1aa61e3
commit
b6e9d1605d
|
@ -254,6 +254,18 @@ def get_date(page):
|
|||
#print(f"Could not parse date")
|
||||
return None
|
||||
|
||||
def parse_headings(page):
|
||||
try:
|
||||
# TODO for some reason this one isn't being parsed by the regex
|
||||
if '= Kitaab =' in page:
|
||||
print(page)
|
||||
page = re.sub(r'= [\[\]a-zA-Z0-9 ]* =',
|
||||
lambda x: x.group().replace('=','#', 1).strip('='),
|
||||
page)
|
||||
return page
|
||||
except Exception as e:
|
||||
print(f"Could not parse headers {e}")
|
||||
return page
|
||||
|
||||
# From the list of files, creates the main array of entries that will be processed later
|
||||
def create_entries(pages):
|
||||
|
@ -278,6 +290,7 @@ def create_entries(pages):
|
|||
markdown_text = remove_tags(markdown_text)
|
||||
markdown_text = remove_title(markdown_text)
|
||||
markdown_text = remove_date(markdown_text)
|
||||
markdown_text = parse_headings(markdown_text)
|
||||
pageContent = markdown(markdown_text)
|
||||
|
||||
# Create the page object with all the informations we need
|
||||
|
@ -286,11 +299,11 @@ def create_entries(pages):
|
|||
tempPage['folder'] = path["folder"]
|
||||
tempPage['parent_url'] = path['parent_url']
|
||||
tempPage['parent_text'] = path['parent_text']
|
||||
tempPage['date'] = path['date']
|
||||
tempPage['iso_date'] = path['date']
|
||||
if date:
|
||||
tempPage['iso_date'] = date
|
||||
tempPage['date'] = date
|
||||
else:
|
||||
tempPage['iso_date'] = path['iso_date']
|
||||
tempPage['date'] = path['iso_date']
|
||||
tempPage['title'] = fix_amp(title)
|
||||
tempPage['pageContent'] = pageContent
|
||||
tempPage['tags'] = tags
|
||||
|
|
Loading…
Reference in a new issue