diff --git a/docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png b/docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png new file mode 100644 index 0000000..114c5fb Binary files /dev/null and b/docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png differ diff --git a/src/vuegen/config_manager.py b/src/vuegen/config_manager.py index d356e4f..82b381a 100644 --- a/src/vuegen/config_manager.py +++ b/src/vuegen/config_manager.py @@ -215,6 +215,28 @@ def _read_description_file(self, folder_path: Path) -> str: return f"{ret}\n" return "" + def _read_home_image_file(self, folder_path: Path) -> str: + """ + Looks for an image file named 'home_image' with any supported image extension + in the given folder. + + Parameters + ---------- + folder_path : Path + Path to the folder where the 'home_image' file might be located. + + Returns + ------- + str + Path to the 'home_image' image file as a string if found, otherwise an + empty string. + """ + for image_format in r.ImageFormat: + candidate = folder_path / f"home_image{image_format.value_with_dot}" + if candidate.exists() and candidate.is_file(): + return str(candidate) + return "" + def _create_subsect_config_fromdir( self, subsection_dir_path: Path, level: int = 2 ) -> Dict[str, Union[str, List[Dict]]]: @@ -334,7 +356,7 @@ def create_yamlconfig_fromdir( # This will be used for the home section of a report "title": self._create_title_fromdir(base_dir_path.name), "description": self._read_description_file(base_dir_path), - "graphical_abstract": "", + "graphical_abstract": self._read_home_image_file(base_dir_path), "logo": "", }, "sections": [], @@ -358,8 +380,11 @@ def create_yamlconfig_fromdir( # could be single plots? else: file_in_main_section_dir = section_dir - if file_in_main_section_dir.name.lower() == "description.md": - continue # Skip description files in the main section + if ( + file_in_main_section_dir.name.lower() == "description.md" + or "home_image" in file_in_main_section_dir.name.lower() + ): + continue # Skip description file and home_image in the main section component_config = self._create_component_config_fromfile( file_in_main_section_dir ) diff --git a/src/vuegen/report.py b/src/vuegen/report.py index b835e0f..e96cedb 100644 --- a/src/vuegen/report.py +++ b/src/vuegen/report.py @@ -100,6 +100,22 @@ def value_with_dot(self): return f".{self.name.lower()}" +class ImageFormat(StrEnum): + """Enum representing supported image file formats.""" + + PNG = auto() + JPG = auto() + JPEG = auto() + SVG = auto() + GIF = auto() + WEBP = auto() + + @property + def value_with_dot(self): + """Return the file extension with the dot.""" + return f".{self.name.lower()}" + + @dataclass class Component: """ diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/docx/quarto_report/quarto_report.qmd b/tests/report_examples/Basic_example_vuegen_demo_notebook/docx/quarto_report/quarto_report.qmd index 2201667..d17143d 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/docx/quarto_report/quarto_report.qmd +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/docx/quarto_report/quarto_report.qmd @@ -27,6 +27,8 @@ report_dir = Path().cwd() A general description of the report. +![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%} + # Plots ## Interactive Plots Optional description for section. diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/html/quarto_report/quarto_report.qmd b/tests/report_examples/Basic_example_vuegen_demo_notebook/html/quarto_report/quarto_report.qmd index ece0fa8..0946b7d 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/html/quarto_report/quarto_report.qmd +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/html/quarto_report/quarto_report.qmd @@ -53,6 +53,8 @@ report_dir = Path().cwd() A general description of the report. +![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%} + # Plots ## Interactive Plots Optional description for section. diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/jupyter/quarto_report/quarto_report.qmd b/tests/report_examples/Basic_example_vuegen_demo_notebook/jupyter/quarto_report/quarto_report.qmd index 38f75d7..eb86015 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/jupyter/quarto_report/quarto_report.qmd +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/jupyter/quarto_report/quarto_report.qmd @@ -53,6 +53,8 @@ report_dir = Path().cwd() A general description of the report. +![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%} + # Plots ## Interactive Plots Optional description for section. diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/odt/quarto_report/quarto_report.qmd b/tests/report_examples/Basic_example_vuegen_demo_notebook/odt/quarto_report/quarto_report.qmd index bc4151c..7e77432 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/odt/quarto_report/quarto_report.qmd +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/odt/quarto_report/quarto_report.qmd @@ -27,6 +27,8 @@ report_dir = Path().cwd() A general description of the report. +![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%} + # Plots ## Interactive Plots Optional description for section. diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/pdf/quarto_report/quarto_report.qmd b/tests/report_examples/Basic_example_vuegen_demo_notebook/pdf/quarto_report/quarto_report.qmd index edf136b..76fe18d 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/pdf/quarto_report/quarto_report.qmd +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/pdf/quarto_report/quarto_report.qmd @@ -39,6 +39,8 @@ report_dir = Path().cwd() A general description of the report. +![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%} + # Plots ## Interactive Plots Optional description for section. diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/pptx/quarto_report/quarto_report.qmd b/tests/report_examples/Basic_example_vuegen_demo_notebook/pptx/quarto_report/quarto_report.qmd index 29d2c4f..bfe6edf 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/pptx/quarto_report/quarto_report.qmd +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/pptx/quarto_report/quarto_report.qmd @@ -28,6 +28,8 @@ report_dir = Path().cwd() A general description of the report. +![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%} + # Plots ## Interactive Plots Optional description for section. diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/revealjs/quarto_report/quarto_report.qmd b/tests/report_examples/Basic_example_vuegen_demo_notebook/revealjs/quarto_report/quarto_report.qmd index 1f12321..ce6e15e 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/revealjs/quarto_report/quarto_report.qmd +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/revealjs/quarto_report/quarto_report.qmd @@ -54,6 +54,8 @@ report_dir = Path().cwd() A general description of the report. +![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%} + # Plots ## Interactive Plots Optional description for section. diff --git a/tests/report_examples/Basic_example_vuegen_demo_notebook/streamlit_report/sections/Home/Homepage.py b/tests/report_examples/Basic_example_vuegen_demo_notebook/streamlit_report/sections/Home/Homepage.py index b7518be..060aec6 100644 --- a/tests/report_examples/Basic_example_vuegen_demo_notebook/streamlit_report/sections/Home/Homepage.py +++ b/tests/report_examples/Basic_example_vuegen_demo_notebook/streamlit_report/sections/Home/Homepage.py @@ -7,6 +7,8 @@ ), unsafe_allow_html=True) + +st.image('docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png', use_column_width=True) footer = '''