Skip to content

Commit dc81b5d

Browse files
authored
Merge pull request #63 from rothgar/reference-api
docs: add api reference docs
2 parents 3eb46ea + 82069e9 commit dc81b5d

14 files changed

Lines changed: 121204 additions & 10654 deletions

File tree

docs-convert/main.go

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ func escapeAngleBracketPlaceholders(line string) string {
243243
result := ""
244244
i := 0
245245
for i < len(line) {
246+
// Check for HTML comment pattern <!--
247+
if i+3 < len(line) && line[i:i+4] == "<!--" {
248+
// Find the closing -->
249+
end := strings.Index(line[i:], "-->")
250+
if end != -1 {
251+
// Extract comment content and convert to MDX format
252+
commentContent := line[i+4 : i+end] // Extract text between <!-- and -->
253+
result += "{/*" + commentContent + "*/}"
254+
i = i + end + 3 // +3 for "-->"
255+
continue
256+
}
257+
}
258+
246259
// Check for Hugo shortcode start pattern {{<
247260
if i+2 < len(line) && line[i:i+3] == "{{<" {
248261
// Find the closing >}}
@@ -266,16 +279,18 @@ func escapeAngleBracketPlaceholders(line string) string {
266279
// Extract the content between < and >
267280
content := line[i+1 : end]
268281
// Check if it's likely a placeholder or text that should not be parsed as HTML
269-
// Known HTML tags we want to preserve: a, br, Accordion, details, summary, pre, code and their closing tags
282+
// Known HTML tags we want to preserve: a, br, p, Accordion, details, summary, pre, code and their closing tags
270283
isKnownTag := strings.HasPrefix(content, "a ") ||
271284
strings.HasPrefix(content, "br") ||
285+
strings.HasPrefix(content, "p") ||
272286
strings.HasPrefix(content, "Accordion") ||
273287
strings.HasPrefix(content, "details") ||
274288
strings.HasPrefix(content, "summary") ||
275289
strings.HasPrefix(content, "pre") ||
276290
strings.HasPrefix(content, "code") ||
277291
content == "/a" ||
278292
content == "/br" ||
293+
content == "/p" ||
279294
content == "/Accordion" ||
280295
content == "/details" ||
281296
content == "/summary" ||
@@ -457,6 +472,10 @@ func processCellContent(content string) string {
457472
// Escape angle bracket placeholders
458473
content = escapeAngleBracketPlaceholders(content)
459474

475+
// Collapse all whitespace (including newlines) into single spaces for MDX compatibility
476+
// This prevents parsing errors with multi-line content in <td> tags
477+
content = strings.Join(strings.Fields(content), " ")
478+
460479
return content
461480
}
462481

@@ -561,12 +580,71 @@ func convertTableToHTML(lines []string, startIdx int) (string, int) {
561580

562581
func main() {
563582
if len(os.Args) < 3 {
564-
fmt.Println("Usage: convert-docs <source_dir> <dest_dir>")
583+
fmt.Println("Usage: convert-docs <source_file_or_dir> <dest_file_or_dir>")
584+
os.Exit(1)
585+
}
586+
587+
src := os.Args[1]
588+
dst := os.Args[2]
589+
590+
// Check if source is a file or directory
591+
srcInfo, err := os.Stat(src)
592+
if err != nil {
593+
fmt.Fprintf(os.Stderr, "Error accessing source: %v\n", err)
565594
os.Exit(1)
566595
}
567596

568-
srcDir := os.Args[1]
569-
dstDir := os.Args[2]
597+
// Single file conversion
598+
if !srcInfo.IsDir() {
599+
if !strings.HasSuffix(src, ".md") {
600+
fmt.Fprintf(os.Stderr, "Error: source file must be a .md file\n")
601+
os.Exit(1)
602+
}
603+
604+
// Skip _index.md files
605+
if strings.Contains(src, "_index.md") {
606+
fmt.Printf("Skipping _index.md file\n")
607+
os.Exit(0)
608+
}
609+
610+
// Determine the destination file path
611+
dstPath := dst
612+
613+
// Check if destination is a directory or should be treated as one
614+
dstInfo, err := os.Stat(dst)
615+
if err == nil && dstInfo.IsDir() {
616+
// Destination exists and is a directory - derive filename from source
617+
srcBase := filepath.Base(src)
618+
dstFilename := strings.TrimSuffix(srcBase, ".md") + ".mdx"
619+
dstPath = filepath.Join(dst, dstFilename)
620+
} else if err != nil && (strings.HasSuffix(dst, "/") || strings.HasSuffix(dst, "\\")) {
621+
// Destination doesn't exist but ends with slash - treat as directory
622+
srcBase := filepath.Base(src)
623+
dstFilename := strings.TrimSuffix(srcBase, ".md") + ".mdx"
624+
dstPath = filepath.Join(dst, dstFilename)
625+
}
626+
627+
fmt.Printf("Converting single file: %s -> %s\n", src, dstPath)
628+
629+
// Create destination directory if it doesn't exist
630+
if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil {
631+
fmt.Fprintf(os.Stderr, "Error creating destination directory: %v\n", err)
632+
os.Exit(1)
633+
}
634+
635+
// Convert the file
636+
if err := convertFile(src, dstPath); err != nil {
637+
fmt.Fprintf(os.Stderr, "Error converting file: %v\n", err)
638+
os.Exit(1)
639+
}
640+
641+
fmt.Println("Conversion complete!")
642+
return
643+
}
644+
645+
// Directory conversion (existing behavior)
646+
srcDir := src
647+
dstDir := dst
570648

571649
fmt.Printf("Converting docs from %s to %s\n", srcDir, dstDir)
572650

@@ -575,7 +653,7 @@ func main() {
575653
os.MkdirAll(dstDir, 0755)
576654

577655
// Walk through source directory
578-
err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
656+
err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
579657
if err != nil {
580658
return err
581659
}

public/docs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
"talos/v1.11/reference/configuration/v1alpha1/config",
307307
"talos/v1.11/reference/kernel",
308308
"talos/v1.11/reference/cli",
309+
"talos/v1.11/reference/api",
309310
"talos/v1.11/reference/configuration/extensions/extensionserviceconfig",
310311
"talos/v1.11/reference/configuration/hardware/pcidriverrebindconfig",
311312
"talos/v1.11/reference/configuration/security/trustedrootsconfig",
@@ -603,6 +604,7 @@
603604
"talos/v1.10/reference/configuration/v1alpha1/config",
604605
"talos/v1.10/reference/kernel",
605606
"talos/v1.10/reference/cli",
607+
"talos/v1.10/reference/api",
606608
"talos/v1.10/reference/configuration/extensions/extensionserviceconfig",
607609
"talos/v1.10/reference/configuration/hardware/pcidriverrebindconfig",
608610
"talos/v1.10/reference/configuration/security/trustedrootsconfig",
@@ -894,6 +896,7 @@
894896
"talos/v1.9/reference/configuration/v1alpha1/config",
895897
"talos/v1.9/reference/kernel",
896898
"talos/v1.9/reference/cli",
899+
"talos/v1.9/reference/api",
897900
"talos/v1.9/reference/configuration/extensions/extensionserviceconfig",
898901
"talos/v1.9/reference/configuration/security/trustedrootsconfig",
899902
"talos/v1.9/reference/configuration/siderolink/siderolinkconfig",
@@ -1177,6 +1180,7 @@
11771180
"talos/v1.8/reference/configuration/v1alpha1/config",
11781181
"talos/v1.8/reference/kernel",
11791182
"talos/v1.8/reference/cli",
1183+
"talos/v1.8/reference/api",
11801184
"talos/v1.8/reference/configuration/extensions/extensionserviceconfig",
11811185
"talos/v1.8/reference/configuration/security/trustedrootsconfig",
11821186
"talos/v1.8/reference/configuration/siderolink/siderolinkconfig",
@@ -1455,6 +1459,7 @@
14551459
"talos/v1.7/reference/configuration/v1alpha1/config",
14561460
"talos/v1.7/reference/kernel",
14571461
"talos/v1.7/reference/cli",
1462+
"talos/v1.7/reference/api",
14581463
"talos/v1.7/reference/configuration/extensions/extensionserviceconfig",
14591464
"talos/v1.7/reference/configuration/siderolink/siderolinkconfig",
14601465
{
@@ -1724,6 +1729,7 @@
17241729
"talos/v1.6/reference/configuration/v1alpha1/config",
17251730
"talos/v1.6/reference/kernel",
17261731
"talos/v1.6/reference/cli",
1732+
"talos/v1.6/reference/api",
17271733
"talos/v1.6/reference/configuration/siderolink/siderolinkconfig",
17281734
{
17291735
"group": "Network",

0 commit comments

Comments
 (0)