Skip to content

Commit

Permalink
Dbt Docs generate, use user provided index.html if found.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsimsek committed Sep 6, 2024
1 parent b35ad46 commit 670630d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/dbt/task/docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 670630d

Please sign in to comment.