From 670630d2e37f63d78703982ca51555a1ba7ea6fa Mon Sep 17 00:00:00 2001 From: ismail simsek <6005685+ismailsimsek@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:53:59 +0200 Subject: [PATCH] Dbt Docs generate, use user provided index.html if found. --- core/dbt/task/docs/generate.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/dbt/task/docs/generate.py b/core/dbt/task/docs/generate.py index 7f238cf4e44..0cb8c1aa2e7 100644 --- a/core/dbt/task/docs/generate.py +++ b/core/dbt/task/docs/generate.py @@ -3,6 +3,7 @@ from dataclasses import replace from datetime import datetime from itertools import chain +from pathlib import Path from typing import Any, Dict, Iterable, List, Optional, Set, Tuple import agate @@ -213,6 +214,15 @@ def get_unique_id_mapping( class GenerateTask(CompileTask): + + def get_docs_index_file_path(self, ) -> str: + for docs_dir in self.config.docs_paths: + index_html = Path(self.config.project_root).joinpath(docs_dir).joinpath("index.html") + if index_html.is_file() and index_html.exists(): + # click.echo(f"Using user provided documentation page: {index_html.as_posix()}") + return index_html.as_posix() + return DOCS_INDEX_FILE_PATH + def run(self) -> CatalogArtifact: compile_results = None if self.args.compile: @@ -228,7 +238,7 @@ def run(self) -> CatalogArtifact: ) shutil.copyfile( - DOCS_INDEX_FILE_PATH, os.path.join(self.config.project_target_path, "index.html") + self.get_docs_index_file_path(), os.path.join(self.config.project_target_path, "index.html") ) for asset_path in self.config.asset_paths: @@ -321,7 +331,7 @@ def run(self) -> CatalogArtifact: read_catalog_data = load_file_contents(catalog_path) # Create new static index file contents - index_data = load_file_contents(DOCS_INDEX_FILE_PATH) + index_data = load_file_contents(self.get_docs_index_file_path()) index_data = index_data.replace('"MANIFEST.JSON INLINE DATA"', read_manifest_data) index_data = index_data.replace('"CATALOG.JSON INLINE DATA"', read_catalog_data)