mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
News download: Fix Next/Previous links not working when the pointed to article failed to download
This commit is contained in:
parent
9d81359d8a
commit
52616a4994
@ -1863,13 +1863,28 @@ class BasicNewsRecipe(Recipe):
|
|||||||
return soup
|
return soup
|
||||||
|
|
||||||
def internal_postprocess_book(self, oeb, opts, log):
|
def internal_postprocess_book(self, oeb, opts, log):
|
||||||
if self.resolve_internal_links and self.article_url_map:
|
|
||||||
seen = set()
|
seen = set()
|
||||||
for item in oeb.spine:
|
for i, item in enumerate(oeb.spine):
|
||||||
for a in item.data.xpath('//*[local-name()="a" and @href]'):
|
for a in item.data.xpath('//*[local-name()="a" and @href]'):
|
||||||
if a.get('rel') == 'calibre-downloaded-from':
|
if (rel := a.get('rel')) == 'calibre-downloaded-from':
|
||||||
continue
|
continue
|
||||||
url = a.get('href')
|
url = a.get('href')
|
||||||
|
if not url:
|
||||||
|
continue
|
||||||
|
if rel in ('articlenextlink', 'articleprevlink'):
|
||||||
|
abshref = item.abshref(url)
|
||||||
|
if abshref not in oeb.manifest.hrefs:
|
||||||
|
if rel == 'articlenextlink':
|
||||||
|
nextitem = oeb.spine[i + 1] if i + 1 < len(oeb.spine) else None
|
||||||
|
else:
|
||||||
|
nextitem = oeb.spine[i - 1] if i else None
|
||||||
|
if nextitem is None:
|
||||||
|
a.text = None
|
||||||
|
a.attrib.pop('href')
|
||||||
|
else:
|
||||||
|
a.set('href', item.relhref(nextitem.href))
|
||||||
|
continue
|
||||||
|
if self.resolve_internal_links and self.article_url_map:
|
||||||
for curl in self.canonicalize_internal_url(url):
|
for curl in self.canonicalize_internal_url(url):
|
||||||
articles = self.article_url_map.get(curl)
|
articles = self.article_url_map.get(curl)
|
||||||
if articles:
|
if articles:
|
||||||
|
@ -225,7 +225,7 @@ class NavBarTemplate(Template):
|
|||||||
up = '../..' if art == number_of_articles_in_feed - 1 else '..'
|
up = '../..' if art == number_of_articles_in_feed - 1 else '..'
|
||||||
href = f'{prefix}{up}/{next_art}/index.html'
|
href = f'{prefix}{up}/{next_art}/index.html'
|
||||||
navbar.text = '| '
|
navbar.text = '| '
|
||||||
navbar.append(A(_('Next'), href=href))
|
navbar.append(A(_('Next'), href=href, rel='articlenextlink'))
|
||||||
href = f'{prefix}../index.html#article_{art}'
|
href = f'{prefix}../index.html#article_{art}'
|
||||||
next(navbar.iterchildren(reversed=True)).tail = ' | '
|
next(navbar.iterchildren(reversed=True)).tail = ' | '
|
||||||
navbar.append(A(_('Section menu'), href=href))
|
navbar.append(A(_('Section menu'), href=href))
|
||||||
@ -235,7 +235,7 @@ class NavBarTemplate(Template):
|
|||||||
if art > 0 and not bottom:
|
if art > 0 and not bottom:
|
||||||
href = f'{prefix}../article_{art - 1}/index.html'
|
href = f'{prefix}../article_{art - 1}/index.html'
|
||||||
next(navbar.iterchildren(reversed=True)).tail = ' | '
|
next(navbar.iterchildren(reversed=True)).tail = ' | '
|
||||||
navbar.append(A(_('Previous'), href=href))
|
navbar.append(A(_('Previous'), href=href, rel='articleprevlink'))
|
||||||
next(navbar.iterchildren(reversed=True)).tail = ' | '
|
next(navbar.iterchildren(reversed=True)).tail = ' | '
|
||||||
if not bottom:
|
if not bottom:
|
||||||
navbar.append(HR())
|
navbar.append(HR())
|
||||||
@ -402,7 +402,7 @@ class TouchscreenNavBarTemplate(Template):
|
|||||||
navbar.append(BR())
|
navbar.append(BR())
|
||||||
# | Previous
|
# | Previous
|
||||||
if art > 0:
|
if art > 0:
|
||||||
link = A(attrs('article_link'),_('Previous'),href=f'{prefix}../article_{art - 1}/index.html')
|
link = A(attrs('article_link'),_('Previous'), rel='articleprevlink', href=f'{prefix}../article_{art - 1}/index.html')
|
||||||
navbar_tr.append(TD(attrs('article_prev'),link))
|
navbar_tr.append(TD(attrs('article_prev'),link))
|
||||||
else:
|
else:
|
||||||
navbar_tr.append(TD(attrs('article_prev'),''))
|
navbar_tr.append(TD(attrs('article_prev'),''))
|
||||||
@ -419,7 +419,7 @@ class TouchscreenNavBarTemplate(Template):
|
|||||||
else f'article_{art + 1}'
|
else f'article_{art + 1}'
|
||||||
up = '../..' if art == number_of_articles_in_feed - 1 else '..'
|
up = '../..' if art == number_of_articles_in_feed - 1 else '..'
|
||||||
|
|
||||||
link = A(attrs('article_link'), _('Next'), href=f'{prefix}{up}/{next_art}/index.html')
|
link = A(attrs('article_link'), _('Next'), rel='articlenextlink', href=f'{prefix}{up}/{next_art}/index.html')
|
||||||
navbar_tr.append(TD(attrs('article_next'),link))
|
navbar_tr.append(TD(attrs('article_next'),link))
|
||||||
navbar_t.append(navbar_tr)
|
navbar_t.append(navbar_tr)
|
||||||
navbar.append(navbar_t)
|
navbar.append(navbar_t)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user