From 37abe466c7635f1608b5dc1192797a4d278cdcfd Mon Sep 17 00:00:00 2001 From: 117503445 Date: Thu, 24 Aug 2023 01:26:45 +0800 Subject: [PATCH] feat: pagination index Signed-off-by: 117503445 --- src/flow_pdf/flow_pdf/worker/html_gen.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/flow_pdf/flow_pdf/worker/html_gen.py b/src/flow_pdf/flow_pdf/worker/html_gen.py index 46bf505..970de60 100644 --- a/src/flow_pdf/flow_pdf/worker/html_gen.py +++ b/src/flow_pdf/flow_pdf/worker/html_gen.py @@ -88,5 +88,23 @@ def mk_html(elements, dest: Path): doc["elements"][i * PER_HTML_ELEMENTS : (i + 1) * PER_HTML_ELEMENTS], doc_in.dir_output / "output" / f"part_{i}.html", ) + + # make index + soup = BeautifulSoup(html, "html.parser") + # add version to head + for k, v in doc["meta"].items(): + soup.html.head.append(soup.new_tag("meta", attrs={"name": k, "content": v})) # type: ignore + + for i in range(0, int(len(doc["elements"]) / PER_HTML_ELEMENTS) + 1): + a = soup.new_tag( + "a", href=f"part_{i}.html", attrs={"class": "part-link"} + ) + a.string = f"part_{i}" + soup.html.body.append(a) # type: ignore + + soup.html.body.append(soup.new_tag("br")) # type: ignore + + file.write_text(doc_in.dir_output / "output" / "index.html", soup.prettify()) + return DocOutParams(), []