Skip to content

Commit 3e72c6e

Browse files
authored
Clean up structure and remove stale code (#25)
* WIP: clean up structure and remove stale code * additional cleanup
1 parent 47be58d commit 3e72c6e

File tree

7 files changed

+111
-417
lines changed

7 files changed

+111
-417
lines changed

config.yaml

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,103 +14,104 @@ hugo:
1414
languageCode: "en-us"
1515
theme: "docsy"
1616

17-
# Content mapping - organized into 4 main categories
1817
content_mapping:
19-
# TUTORIALS - Step-by-step guides for users
18+
# set 'enable_category_indices' to true to generate _index.md files for categories
19+
# also necessary to enable category menus in Sidebar
20+
# When set to false it shows a monolithic list of all pages
21+
# under the 'docs' menu item
22+
enable_category_indices: false
2023
tutorials:
21-
type: "tutorials"
22-
weight: 10
23-
category: "Tutorials"
24+
type: "docs"
25+
weight: 1
26+
category: "tutorials"
2427
start:
25-
type: "tutorials"
26-
weight: 20
27-
category: "Tutorials"
28+
type: "docs"
29+
weight: 2
30+
category: "tutorials"
2831
basics:
29-
type: "tutorials"
30-
weight: 30
31-
category: "Tutorials"
32-
33-
# HOW-TO GUIDES - Practical instructions for specific tasks
32+
type: "docs"
33+
weight: 3
34+
category: "tutorials"
3435
install:
35-
type: "how-to-guides"
36-
weight: 10
37-
category: "How-To Guides"
36+
type: "docs"
37+
weight: 1
38+
category: "how-to-guides"
3839
configure:
39-
type: "how-to-guides"
40-
weight: 20
41-
category: "How-To Guides"
40+
type: "docs"
41+
weight: 2
42+
category: "how-to-guides"
4243
build:
43-
type: "how-to-guides"
44-
weight: 30
45-
category: "How-To Guides"
44+
type: "docs"
45+
weight: 3
46+
category: "how-to-guides"
4647
run:
47-
type: "how-to-guides"
48-
weight: 40
49-
category: "How-To Guides"
48+
type: "docs"
49+
weight: 4
50+
category: "how-to-guides"
5051
remote:
51-
type: "how-to-guides"
52-
weight: 50
53-
category: "How-To Guides"
52+
type: "docs"
53+
weight: 5
54+
category: "how-to-guides"
5455
migrate:
55-
type: "how-to-guides"
56-
weight: 60
57-
category: "How-To Guides"
56+
type: "docs"
57+
weight: 6
58+
category: "how-to-guides"
5859
rules:
59-
type: "how-to-guides"
60-
weight: 70
61-
category: "How-To Guides"
60+
type: "docs"
61+
weight: 7
62+
category: "how-to-guides"
6263
docs:
63-
type: "how-to-guides"
64-
weight: 80
65-
category: "How-To Guides"
66-
67-
# EXPLANATIONS - In-depth articles explaining concepts and features
64+
type: "docs"
65+
weight: 8
66+
category: "how-to-guides"
67+
brand:
68+
type: "docs"
69+
weight: 9
70+
category: "how-to-guides"
6871
concepts:
69-
type: "explanations"
70-
weight: 10
71-
category: "Explanations"
72+
type: "docs"
73+
weight: 1
74+
category: "explanations"
7275
extending:
73-
type: "explanations"
74-
weight: 20
75-
category: "Explanations"
76+
type: "docs"
77+
weight: 2
78+
category: "explanations"
7679
external:
77-
type: "explanations"
78-
weight: 30
79-
category: "Explanations"
80+
type: "docs"
81+
weight: 3
82+
category: "explanations"
8083
about:
81-
type: "explanations"
82-
weight: 40
83-
category: "Explanations"
84+
type: "docs"
85+
weight: 4
86+
category: "explanations"
8487
community:
85-
type: "explanations"
86-
weight: 50
87-
category: "Explanations"
88+
type: "docs"
89+
weight: 5
90+
category: "explanations"
8891
contribute:
89-
type: "explanations"
90-
weight: 60
91-
category: "Explanations"
92+
type: "docs"
93+
weight: 6
94+
category: "explanations"
9295
release:
93-
type: "explanations"
94-
weight: 70
95-
category: "Explanations"
96-
97-
# REFERENCE - Detailed reference material for advanced users
96+
type: "docs"
97+
weight: 7
98+
category: "explanations"
9899
reference:
99-
type: "reference"
100-
weight: 10
101-
category: "Reference"
100+
type: "docs"
101+
weight: 1
102+
category: "reference"
102103
query:
103-
type: "reference"
104-
weight: 20
105-
category: "Reference"
104+
type: "docs"
105+
weight: 2
106+
category: "reference"
106107
versions:
107-
type: "reference"
108-
weight: 30
109-
category: "Reference"
108+
type: "docs"
109+
weight: 3
110+
category: "reference"
110111
advanced:
111-
type: "reference"
112-
weight: 40
113-
category: "Reference"
112+
type: "docs"
113+
weight: 4
114+
category: "reference"
114115

115116
# CSS conversion settings
116117
css_conversion:

devsite_to_hugo_converter.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def convert_documentation(self,
8686
return False
8787

8888
# Convert content files
89-
conversion_stats = self._convert_content_files(
90-
devsite_structure, source_path, output_path, dry_run,
89+
conversion_stats = self._convert_content_files(source_path, output_path, dry_run,
9190
incremental)
9291

9392
# Convert static assets
@@ -140,8 +139,10 @@ def _create_output_structure(self, output_path: str) -> None:
140139
dir_path.mkdir(parents=True, exist_ok=True)
141140
logger.debug(f"Created directory: {dir_path}")
142141

143-
def _convert_content_files(self, devsite_structure: Dict, source_path: str,
144-
output_path: str, dry_run: bool,
142+
def _convert_content_files(self,
143+
source_path: str,
144+
output_path: str,
145+
dry_run: bool,
145146
incremental: bool) -> Dict:
146147
"""Convert all content files from Devsite to Hugo format"""
147148
conversion_stats = {
@@ -172,9 +173,10 @@ def _convert_content_files(self, devsite_structure: Dict, source_path: str,
172173
category_path = self._get_category_path(relative_path)
173174

174175
# Convert file
176+
if category_path == Path("how-to-guides"):
177+
raise Exception(f"{category_path} is not a valid category. Please update config.yaml to use 'docs' or 'tutorials' instead.")
175178
if self._convert_single_file(
176-
md_file, output_dir / 'content' / category_path,
177-
devsite_structure, dry_run):
179+
md_file, output_dir / 'content' / category_path, dry_run):
178180
conversion_stats['converted_files'] += 1
179181
else:
180182
conversion_stats['error_files'] += 1
@@ -193,6 +195,11 @@ def _get_category_path(self, relative_path: Path) -> Path:
193195
return relative_path
194196

195197
section_name = parts[0]
198+
199+
# Orphan file like "help.md" -> put under Reference
200+
if len(parts) == 1 and parts[0] == "help.md":
201+
logger.info(f"Orphan file {parts[0]} detected, placing under 'reference' category")
202+
return Path("docs") / Path("reference") / parts[0]
196203

197204
# Look up the category for this section
198205
if section_name in self.config['content_mapping']:
@@ -201,12 +208,9 @@ def _get_category_path(self, relative_path: Path) -> Path:
201208

202209
# Return path with category prefix
203210
return Path(category_type) / relative_path
204-
205-
# Default to original path if no mapping found
206-
return relative_path
211+
raise Exception(f"No category mapping found for section '{section_name}', using original path")
207212

208-
def _convert_single_file(self, source_file: Path, output_file: Path,
209-
devsite_structure: Dict, dry_run: bool) -> bool:
213+
def _convert_single_file(self, source_file: Path, output_file: Path, dry_run: bool) -> bool:
210214
"""Convert a single markdown file from Devsite to Hugo format"""
211215
try:
212216
# Read source file
@@ -217,9 +221,7 @@ def _convert_single_file(self, source_file: Path, output_file: Path,
217221
frontmatter, body = self._parse_markdown_file(content)
218222

219223
# Convert frontmatter to Hugo format
220-
hugo_frontmatter = self._convert_frontmatter(
221-
frontmatter, source_file, devsite_structure)
222-
224+
hugo_frontmatter = self._convert_frontmatter(frontmatter=frontmatter)
223225
# Extract title from H1 if not present in frontmatter
224226
title_from_h1 = None
225227
h1_match = re.search(r'^# (.+)$', body, re.MULTILINE)
@@ -277,8 +279,7 @@ def _parse_markdown_file(self, content: str) -> Tuple[Dict, str]:
277279

278280
return {}, content
279281

280-
def _convert_frontmatter(self, frontmatter: Dict, source_file: Path,
281-
devsite_structure: Dict) -> Dict:
282+
def _convert_frontmatter(self, frontmatter: Dict) -> Dict:
282283
"""Convert Devsite frontmatter to Hugo format"""
283284
hugo_frontmatter = {}
284285

@@ -296,7 +297,6 @@ def _convert_frontmatter(self, frontmatter: Dict, source_file: Path,
296297
hugo_frontmatter[hugo_field] = frontmatter[devsite_field]
297298

298299
# Add Hugo-specific fields
299-
hugo_frontmatter['type'] = 'docs' # Default to docs template
300300
hugo_frontmatter['weight'] = frontmatter.get('weight', 1)
301301

302302
# Add title from H1 if not present in frontmatter
@@ -309,10 +309,6 @@ def _convert_frontmatter(self, frontmatter: Dict, source_file: Path,
309309
if 'title' in hugo_frontmatter and 'linkTitle' not in hugo_frontmatter:
310310
hugo_frontmatter['linkTitle'] = hugo_frontmatter['title']
311311

312-
# Add date if not present
313-
if 'date' not in hugo_frontmatter:
314-
hugo_frontmatter['date'] = '2024-01-01'
315-
316312
return hugo_frontmatter
317313

318314
def _convert_body_content(self, body: str) -> str:
@@ -640,10 +636,6 @@ def _generate_hugo_config(self, output_path: str) -> None:
640636
"""Generate Hugo configuration file"""
641637
self.hugo_generator.generate_config(output_path)
642638

643-
def _generate_layouts(self, output_path: str) -> None:
644-
"""Generate Hugo layout templates"""
645-
self.hugo_generator.generate_layouts(output_path)
646-
647639
def _generate_section_indices(self, devsite_structure: Dict,
648640
output_path: str) -> None:
649641
"""Generate _index.md files for Hugo sections"""

templates/hugo_config.yaml.jinja2

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,6 @@ markup:
5454
math:
5555
enable: false
5656

57-
# Menu configuration
58-
menu:
59-
main:
60-
- name: "Tutorials"
61-
url: "/tutorials/"
62-
weight: 10
63-
- name: "How-To Guides"
64-
url: "/how-to-guides/"
65-
weight: 20
66-
- name: "Explanations"
67-
url: "/explanations/"
68-
weight: 30
69-
- name: "Reference"
70-
url: "/reference/"
71-
weight: 40
72-
- name: "Community"
73-
url: "/explanations/community/"
74-
weight: 50
75-
- name: "About"
76-
url: "/explanations/about/"
77-
weight: 60
78-
7957
# Parameters for Docsy theme
8058
params:
8159
# Repository information
@@ -92,11 +70,7 @@ params:
9270
# Navigation configuration
9371
navigation:
9472
depth: 4
95-
96-
# Footer configuration
97-
footer:
98-
enable: false
99-
73+
10074
# Disable math rendering
10175
katex:
10276
enable: false

templates/index_md.jinja2

Lines changed: 0 additions & 16 deletions
This file was deleted.

templates/section_index.jinja2

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
---
22
title: "{{ section.title }}"
3-
linkTitle: "{{ section.linkTitle | default(section.title) }}"
3+
{% if section.linkTitle %}linkTitle: "{{ section.linkTitle }}"{% endif %}
44
{% if section.description %}description: "{{ section.description }}"{% endif %}
5-
type: "{{ section.type | default('docs') }}"
6-
weight: {{ section.weight | default(1) }}
5+
{% if section.type %}type: "{{ section.type }}"{% endif %}
6+
{% if section.weight%}weight: "{{ section.weight }}"{% endif %}
7+
{% if 'cascade' in section and section.cascade.type is defined %}
78
cascade:
8-
type: "{{ section.type | default('docs') }}"
9+
type: "{{ section.cascade.type }}"{% endif %}
910
---
10-
11-
# {{ section.title }}
12-
13-
{% if section.description %}
14-
{{ section.description }}
15-
{% endif %}
16-
17-
{% if section.overview %}
18-
{{ section.overview }}
19-
{% endif %}
20-
21-
{% if section.subsections %}
22-
## Subsections
23-
24-
{% for subsection in section.subsections %}
25-
- [{{ subsection.title }}]({{ subsection.path }}){% if subsection.description %} - {{ subsection.description }}{% endif %}
26-
{% endfor %}
27-
{% endif %}

0 commit comments

Comments
 (0)