Move the tag linking code to helper function.

This commit is contained in:
Ethan Dalool 2020-03-23 13:27:56 -07:00
parent 3b26548a06
commit 1f8aca018c

View file

@ -104,6 +104,15 @@ def git_file_published_date(path):
output = subprocess.check_output(command, stderr=subprocess.PIPE).decode('utf-8') output = subprocess.check_output(command, stderr=subprocess.PIPE).decode('utf-8')
return output return output
def soup_set_tag_links(soup):
tag_links = soup.find_all('a', {'class': 'tag_link'})
for tag_link in tag_links:
tagname = tag_link['data-qualname'].split('.')[-1]
tag_link['href'] = f'/writing/tags/{tagname}'
tags = [a['data-qualname'] for a in tag_links]
return tags
class Article: class Article:
def __init__(self, md_file): def __init__(self, md_file):
self.md_file = pathclass.Path(md_file) self.md_file = pathclass.Path(md_file)
@ -139,12 +148,7 @@ class Article:
else: else:
self.title = self.md_file.basename self.title = self.md_file.basename
tag_links = self.soup.find_all('a', {'class': 'tag_link'}) self.tags = soup_set_tag_links(self.soup)
for tag_link in tag_links:
tagname = tag_link['data-qualname'].split('.')[-1]
tag_link['href'] = f'/writing/tags/{tagname}'
self.tags = [a['data-qualname'] for a in tag_links]
def __repr__(self): def __repr__(self):
return f'Article:{self.title}' return f'Article:{self.title}'