Skip to content

Commit

Permalink
Merge branch 'release/1.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
lb803 committed Mar 6, 2023
2 parents c6c8968 + 66a03d9 commit f4271c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
22 changes: 6 additions & 16 deletions src/epublius/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,22 @@ def get_file_soup(self):

def get_chapter_title(self):
'''
Retrieve chapter title based on the text of <h1> or
Retrieve chapter title based on the text of <title> or
taking a guess from the file name
(i.e. front-cover.xhtml -> "Front Cover")
Special characters in the title are escaped before
the ch_title varible is returned.
'''

h1 = self.soup.find_all('h1')

if len(h1) == 1:
ch_title = self.soup.h1.get_text()

elif len(h1) > 1:
print("[WARNING] {} has multiple h1 tags"
.format(self.contents[self.index]))
ch_title = h1.pop(0).get_text()
title_node = self.soup.title

if (title_node is not None) and \
(title_node.string is not None):
ch_title = title_node.string
else:
# Strip extension from file name
basename = self.contents[self.index].split('.')[0]

# Replace hypens with spaces (if any)
basename = os.path.splitext(self.contents[self.index])[0]
title_words = basename.replace('-', ' ')

# Create a titlecased version of title words
ch_title = title_words.title()

return html.escape(ch_title)
Expand Down
16 changes: 9 additions & 7 deletions src/thoth_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ def get_title(thoth_data):
def get_html_pub_url(thoth_data):
for publication in thoth_data["publications"]:
if publication['publicationType'] == 'HTML':
try:
url = publication['locations'][0]['fullTextUrl']
except IndexError:
raise IndexError('HTML edition defined in Thoth but '
'location URL not specified. Please, '
'add it and re-run the process.')
locations = publication.get('locations', [])
break
else:
raise SystemExit('HTML edition data not found in Thoth.',
raise ValueError('HTML edition data not found in Thoth.',
'Please add it and re-run the process.')

try:
url = locations[0]['fullTextUrl']
except IndexError:
raise IndexError('HTML edition defined in Thoth but '
'location URL not specified. Please, '
'add it and re-run the process.')

return url

def run():
Expand Down

0 comments on commit f4271c4

Please sign in to comment.