Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html title #12

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion leda/gen/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class Report:
name: str

html_title: str | None = None
tag: str | None = None

params: Mapping[str, Any] | None = None
Expand Down Expand Up @@ -101,7 +102,7 @@ class ReportArtifact:
@dataclasses.dataclass()
class ReportGenerator:
def generate(
self, nb_contents: nbformat.NotebookNode, nb_name: str | None = None
self, nb_contents: nbformat.NotebookNode, html_title: str | None = None
) -> bytes:
raise NotImplementedError

Expand Down
6 changes: 3 additions & 3 deletions leda/gen/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _get_exporter_kwargs(self) -> dict:
def generate(
self,
nb_contents: nbformat.NotebookNode,
nb_name: str | None = None,
html_title: str | None = None,
) -> bytes:
logger.info("Generating notebook")
preprocessor = self._get_preprocessor()
Expand All @@ -154,9 +154,9 @@ def generate(
body, _ = exporter.from_notebook_node(nb_contents)

logger.info("Modifying HTML")
if nb_name:
if html_title:
body = body.replace(
"<title>Notebook</title>", f"<title>{nb_name}</title>"
"<title>Notebook</title>", f"<title>{html_title}</title>"
)

return body.encode(errors="ignore")
4 changes: 3 additions & 1 deletion leda/gen/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def run(self, report: leda.gen.base.Report) -> str | None:

self.modifier.modify(nb_contents)

body = self.generator.generate(nb_contents, nb_name=report.name)
html_title = report.html_title if report.html_title else report.name

body = self.generator.generate(nb_contents, html_title=html_title)
artifact = leda.gen.base.ReportArtifact(body)

return self.publisher.publish(report, artifact)
Expand Down
Loading