Skip to content

Commit

Permalink
html title (#12)
Browse files Browse the repository at this point in the history
- adds html_title to Report class so that we can customize the html title of a report
- renames nb_name to html_title in the ReportGenerator, as it was only being used for setting the html title anyway
  • Loading branch information
hyukim17 authored Feb 24, 2024
1 parent ca3b679 commit e27dbe6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion leda/gen/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class Report:
name: str

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

params: Mapping[str, Any] | None = None
Expand Down Expand Up @@ -105,7 +106,7 @@ class ReportArtifact:
class ReportGenerator:
@abc.abstractmethod
def generate(
self, nb_contents: nbformat.NotebookNode, nb_name: str | None = None
self, nb_contents: nbformat.NotebookNode, html_title: str | None = None
) -> bytes:
...

Expand Down
6 changes: 3 additions & 3 deletions leda/gen/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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 @@ -158,9 +158,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 @@ -29,7 +29,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

0 comments on commit e27dbe6

Please sign in to comment.