diff --git a/pelican/plugins/quarto/adapters.py b/pelican/plugins/quarto/adapters.py new file mode 100644 index 0000000..c31a74c --- /dev/null +++ b/pelican/plugins/quarto/adapters.py @@ -0,0 +1,61 @@ +import logging +from pathlib import Path +import subprocess + +logger = logging.getLogger(__name__) + + +class Quarto: + """Adapter Class for establishing and running Quarto.""" + + def __init__(self, path, output_path): + self.path = Path(path) + self.wdir = self.path.parent + self.output_path = output_path + self._setup_quarto_project() + + def _setup_quarto_project(self): + content_dir = self.path + quarto_config_path = content_dir / "_quarto.yml" + content_dir.mkdir(parents=True, exist_ok=True) + + if quarto_config_path.exists(): + logger.info( + f"_quarto.yml already exists at {quarto_config_path}, skipping setup." + ) + return + + output_dir_abs = self.wdir / self.output_path + + quarto_config = f""" +project: + type: website + output-dir: {output_dir_abs} + +format: + html: + theme: none + """ + with open(quarto_config_path, "w") as config_file: + config_file.write(quarto_config) + logger.info(f"_quarto.yml created at {quarto_config_path}") + + def run_quarto(self, filename): + try: + result = subprocess.run( + ["quarto", "render", filename, "--output", "-"], + cwd=str(Path(self.wdir) / "content"), + capture_output=True, + text=True, + check=False, + ) + if result.returncode == 0: + logger.info("Quarto render completed successfully.") + return result.stdout + logger.error( + f"Error while rendering Quarto Markdown File {filename}: {result.stderr}" + ) + return result.stderr + + except Exception: + logger.error("An exception occured while running Quarto: {e}") diff --git a/pelican/plugins/quarto/parsers.py b/pelican/plugins/quarto/parsers.py new file mode 100644 index 0000000..446f28d --- /dev/null +++ b/pelican/plugins/quarto/parsers.py @@ -0,0 +1,32 @@ +from bs4 import BeautifulSoup + + +class QuartoHTML: + """Facade to Quarto HTML Documents.""" + + def __init__(self, html_string): + self.soup = BeautifulSoup(html_string, "html.parser") + self.header = self._extract_header() + self.body = self._extract_body() + self.header_scripts_links = self._extract_header_scripts_links() + self.header_styles = self._extract_header_styles() + + def _extract_header(self): + header = self.soup.find("head") + return str(header) if header else "" + + def _extract_header_scripts_links(self): + """Extract + + + + + + + + social + + atom feed + + + + + + + +