Skip to content

Commit

Permalink
Fix doc link checker to handle GitHub md changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed Jul 12, 2023
1 parent f2b6ed0 commit edf5da1
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions utils/linkcheck/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -275,14 +275,12 @@ func checkURL(urlToGet *url.URL, fragments []string) int {

fmt.Println(" OK")

pageContent := string(content)

for _, fragment := range fragments {
if fragment != "" {
fmt.Printf("%s#%s", urlToGet, fragment)
heading1 := fmt.Sprintf("id=\"%s\"", fragment)
heading2 := fmt.Sprintf("id=%s", fragment)
heading3 := fmt.Sprintf("href=\"#%s\"", fragment)
if !strings.Contains(string(content), heading1) && !strings.Contains(string(content), heading2) && !strings.Contains(string(content), heading3) {
fmt.Printf(" FAILED could not find heading %s %s or %s on page\n", heading1, heading2, heading3)
if !checkFragment(fragment, pageContent) {
return 1
}
fmt.Println(" OK")
Expand All @@ -295,6 +293,27 @@ func checkURL(urlToGet *url.URL, fragments []string) int {
return 0
}

func checkFragment(fragment, pageContent string) bool {
var headings []string

headings = append(headings, fmt.Sprintf("id=\"%s\"", fragment))
headings = append(headings, fmt.Sprintf("id=%s", fragment))
headings = append(headings, fmt.Sprintf("href=\"#%s\"", fragment))
headings = append(headings, fmt.Sprintf("href=\\\"#%s\\\"", fragment))

for _, heading := range headings {
if strings.Contains(pageContent, heading) {
return true
}
}

fmt.Println(" FAILED could not find any of the following headings:")
for _, heading := range headings {
fmt.Printf(" %s", heading)
}
return false
}

func parseLinks(content string, excludes []string) ([]string, map[string][]string, error) {
var (
err error
Expand Down

0 comments on commit edf5da1

Please sign in to comment.