Skip to content

Commit

Permalink
fix: timeout option not being honored
Browse files Browse the repository at this point in the history
Fixes #30.
  • Loading branch information
adrienbrignon committed Jul 23, 2024
1 parent 53c84e7 commit b45c531
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 99 deletions.
3 changes: 2 additions & 1 deletion mkdocs_exporter/formats/pdf/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def preprocess(self, page: Page) -> str:

preprocessor.teleport()
preprocessor.metadata({
'page': sum(page.formats['pdf']['pages'] - page.formats['pdf']['skipped_pages'] for page in self.pages[:page.index]),
'page': sum(page.formats['pdf']['pages'] - page.formats['pdf']['skipped_pages'] for page in self.pages[:page.index]) + 1,
'pages': sum(page.formats['pdf']['pages'] - page.formats['pdf']['skipped_pages'] for page in self.pages),
})

Expand Down Expand Up @@ -103,6 +103,7 @@ def _skip(self, page: Page, covers: list[str]) -> Aggregator:
for cover in covers:
if cover in page.formats['pdf']['covers']:
page.formats['pdf']['covers'].remove(cover)

page.formats['pdf']['skipped_pages'] = page.formats['pdf']['skipped_pages'] + 1

return self
4 changes: 2 additions & 2 deletions mkdocs_exporter/formats/pdf/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ async def print(self, html: str) -> tuple[bytes, int]:
file.write(html)
file.close()

await context.goto('file://' + file.name, wait_until='networkidle')
await context.goto('file://' + file.name, wait_until='networkidle', timeout=self.timeout)
await context.locator('body[mkdocs-exporter="true"]').wait_for(timeout=self.timeout)

pages = int(await context.locator('body').get_attribute('mkdocs-exporter-pages') or 0)
pages = int(await context.locator('body').get_attribute('mkdocs-exporter-pages', timeout=self.timeout) or 0)
pdf = await context.pdf(prefer_css_page_size=True, print_background=True, display_header_footer=False)

await context.close()
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_exporter/formats/pdf/resources/js/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ window.PagedConfig = {
}

if ('page' in __MKDOCS_EXPORTER__ && pages.children[0]) {
pages.children[0].style.setProperty('counter-reset', `page ${__MKDOCS_EXPORTER__.page}`);
pages.children[0].style.setProperty('counter-set', `page ${__MKDOCS_EXPORTER__.page}`);
}
}
}
Expand Down
Loading

0 comments on commit b45c531

Please sign in to comment.