MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / generate

Method generate

codewiki/cli/html_generator.py:83–171  ·  view source on GitHub ↗

Generate HTML documentation viewer. Args: output_path: Output file path (index.html) title: Documentation title module_tree: Module tree structure (auto-loaded from docs_dir if not provided) repository_url: GitHub repository U

(
        self,
        output_path: Path,
        title: str,
        module_tree: Optional[Dict[str, Any]] = None,
        repository_url: Optional[str] = None,
        github_pages_url: Optional[str] = None,
        config: Optional[Dict[str, Any]] = None,
        docs_dir: Optional[Path] = None,
        metadata: Optional[Dict[str, Any]] = None
    )

Source from the content-addressed store, hash-verified

81 self,
82 output_path: Path,
83 title: str,
84 module_tree: Optional[Dict[str, Any]] = None,
85 repository_url: Optional[str] = None,
86 github_pages_url: Optional[str] = None,
87 config: Optional[Dict[str, Any]] = None,
88 docs_dir: Optional[Path] = None,
89 metadata: Optional[Dict[str, Any]] = None,
90 ):
91 """
92 Generate HTML documentation viewer.
93
94 Args:
95 output_path: Output file path (index.html)
96 title: Documentation title
97 module_tree: Module tree structure (auto-loaded from docs_dir if not provided)
98 repository_url: GitHub repository URL
99 github_pages_url: Expected GitHub Pages URL
100 config: Additional configuration
101 docs_dir: Documentation directory (for auto-loading module_tree and metadata)
102 metadata: Metadata dictionary (auto-loaded from docs_dir if not provided)
103 """
104 # Auto-load module_tree and metadata from docs_dir if not provided
105 if docs_dir:
106 if module_tree is None:
107 module_tree = self.load_module_tree(docs_dir)
108 if metadata is None:
109 metadata = self.load_metadata(docs_dir)
110
111 # Default values
112 if module_tree is None:
113 module_tree = {}
114 if config is None:
115 config = {}
116
117 # Load template
118 template_path = self.template_dir / "viewer_template.html"
119 if not template_path.exists():
120 raise FileSystemError(f"Template not found: {template_path}")
121
122 template_content = safe_read(template_path)
123
124 # Build info content HTML
125 info_content = self._build_info_content(metadata)
126 show_info = "block" if info_content else "none"
127
128 # Build repository link
129 repo_link = ""
130 if repository_url:
131 repo_link = f'<a href="{repository_url}" class="repo-link" target="_blank">🔗 View Repository</a>'
132
133 # Determine docs base path
134 # For GitHub Pages: relative path to docs folder
135 # For local: relative path to docs folder
136 docs_base_path = ""
137 if docs_dir and output_path.parent != docs_dir:
138 # Calculate relative path from output to docs
139 try:
140 docs_base_path = Path(docs_dir.name).as_posix()

Callers 1

_run_html_generationMethod · 0.95

Calls 7

load_module_treeMethod · 0.95
load_metadataMethod · 0.95
_build_info_contentMethod · 0.95
_escape_htmlMethod · 0.95
FileSystemErrorClass · 0.90
safe_readFunction · 0.90
safe_writeFunction · 0.90

Tested by

no test coverage detected