fix: Cleanup

This commit is contained in:
Ilya Kuznetsov 2024-12-12 13:05:55 +01:00
parent aed0e0a92f
commit 5194889605
No known key found for this signature in database
GPG Key ID: 91F3DDCF5D21CDDF
1 changed files with 5 additions and 8 deletions

View File

@ -170,32 +170,29 @@ func convertLinksToAbsoluteUrl(s string) string {
base := "https://docs.databricks.com" base := "https://docs.databricks.com"
referencePage := "/dev-tools/bundles/reference.html" referencePage := "/dev-tools/bundles/reference.html"
// Regular expression to match Markdown-style links // Regular expression to match Markdown-style links like [_](link)
re := regexp.MustCompile(`\[_\]\(([^)]+)\)`) re := regexp.MustCompile(`\[_\]\(([^)]+)\)`)
result := re.ReplaceAllStringFunc(s, func(match string) string { result := re.ReplaceAllStringFunc(s, func(match string) string {
// Extract the URL inside parentheses
matches := re.FindStringSubmatch(match) matches := re.FindStringSubmatch(match)
if len(matches) < 2 { if len(matches) < 2 {
return match // Return original if no match found return match
} }
link := matches[1] link := matches[1]
var text, absoluteURL string var text, absoluteURL string
if strings.HasPrefix(link, "#") { if strings.HasPrefix(link, "#") {
text = strings.TrimPrefix(link, "#") text = strings.TrimPrefix(link, "#")
absoluteURL = fmt.Sprintf("%s%s%s", base, referencePage, link) absoluteURL = fmt.Sprintf("%s%s%s", base, referencePage, link)
} else if strings.HasPrefix(link, "/") {
// Handle relative paths like /dev-tools/bundles/resources.html#dashboard // Handle relative paths like /dev-tools/bundles/resources.html#dashboard
} else if strings.HasPrefix(link, "/") {
absoluteURL = strings.ReplaceAll(fmt.Sprintf("%s%s", base, link), ".md", ".html")
if strings.Contains(link, "#") { if strings.Contains(link, "#") {
parts := strings.Split(link, "#") parts := strings.Split(link, "#")
text = parts[1] text = parts[1]
absoluteURL = fmt.Sprintf("%s%s", base, link)
} else { } else {
text = "link" text = "link"
absoluteURL = fmt.Sprintf("%s%s", base, link)
} }
absoluteURL = strings.ReplaceAll(absoluteURL, ".md", ".html")
} else { } else {
return match return match
} }