/ docs / scripts / fix_link_patterns.jl
fix_link_patterns.jl
 1  #!/usr/bin/env julia
 2  
 3  """
 4  Fix Link Patterns Script
 5  
 6  This script analyzes and fixes the most common link pattern issues.
 7  """
 8  
 9  using Pkg
10  Pkg.activate("docs")
11  
12  # First, let's analyze the most common broken link patterns
13  function analyze_broken_links()
14      println("=== ANALYZING BROKEN LINK PATTERNS ===")
15      
16      # Read a few key files to understand the link patterns
17      files_to_check = [
18          "docs/src/config.md",
19          "docs/src/data.md", 
20          "docs/src/strategy.md",
21          "docs/src/optimization.md"
22      ]
23      
24      link_patterns = Dict{String, Int}()
25      
26      for file_path in files_to_check
27          if isfile(file_path)
28              content = read(file_path, String)
29              lines = split(content, '\n')
30              
31              for (i, line) in enumerate(lines)
32                  # Find markdown links
33                  for m in eachmatch(r"\[([^\]]*)\]\(([^)]+)\)", line)
34                      link_text = m.captures[1]
35                      link_url = m.captures[2]
36                      
37                      # Skip external links
38                      if !startswith(link_url, "http")
39                          pattern = link_url
40                          link_patterns[pattern] = get(link_patterns, pattern, 0) + 1
41                          
42                          # Check if target exists
43                          if startswith(link_url, "../")
44                              # Try different resolution strategies
45                              target1 = normpath(joinpath(dirname(file_path), link_url))
46                              target2 = normpath(joinpath("docs/src", link_url[4:end])) # Remove ../
47                              target3 = normpath(joinpath("docs", link_url[4:end])) # Remove ../
48                              
49                              exists1 = isfile(target1) || isdir(target1)
50                              exists2 = isfile(target2) || isdir(target2)  
51                              exists3 = isfile(target3) || isdir(target3)
52                              
53                              if !exists1 && !exists2 && !exists3
54                                  println("BROKEN: $file_path:$i -> $link_url")
55                                  println("  Tried: $target1 ($(exists1))")
56                                  println("  Tried: $target2 ($(exists2))")
57                                  println("  Tried: $target3 ($(exists3))")
58                              elseif !exists1 && (exists2 || exists3)
59                                  correct_target = exists2 ? target2 : target3
60                                  println("FIXABLE: $file_path:$i -> $link_url should point to $correct_target")
61                              end
62                          end
63                      end
64                  end
65              end
66          end
67      end
68      
69      println("\nMost common link patterns:")
70      sorted_patterns = sort(collect(link_patterns), by=x->x[2], rev=true)
71      for (pattern, count) in sorted_patterns[1:min(20, end)]
72          println("  $count times: $pattern")
73      end
74  end
75  
76  # Run the analysis
77  analyze_broken_links()
78  
79  println("\n=== CHECKING FILE EXISTENCE ===")
80  # Check what files actually exist
81  key_files = [
82      "docs/src/config.md",
83      "docs/src/exchanges.md", 
84      "docs/src/optimization.md",
85      "docs/src/guides/strategy-development.md",
86      "docs/src/guides/data-management.md",
87      "docs/src/guides/execution-modes.md",
88      "docs/troubleshooting/index.md",
89      "docs/troubleshooting/exchange-issues.md",
90      "docs/troubleshooting/performance-issues.md",
91      "docs/troubleshooting/installation-issues.md",
92      "docs/getting-started/installation.md"
93  ]
94  
95  for file in key_files
96      exists = isfile(file)
97      println("$file: $(exists ? "✅ EXISTS" : "❌ MISSING")")
98  end