-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix links in fields doc (#3539)
- Loading branch information
Showing
6 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !fields | ||
|
||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build fields | ||
|
||
package main | ||
|
||
func generateDocs() { | ||
panic("hack package was built with 'fields' tag; doc generation code was not included") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"regexp" | ||
) | ||
|
||
const ( | ||
newHeader = `<summary>Examples with this field (click to open)</summary> | ||
<br> | ||
<ul>` | ||
newHeaderAlt = `<summary>Examples (click to open)</summary> | ||
<br> | ||
<ul>` | ||
newLink = ` <li> <a href="$2">$1</a>` | ||
newDetails = `</ul> | ||
</details>` | ||
) | ||
|
||
var ( | ||
headerRegex = regexp.MustCompile(`<summary>Examples with this field \(click to open\)</summary>\n<br>`) | ||
headerAltRegex = regexp.MustCompile(`<summary>Examples \(click to open\)</summary>\n<br>`) | ||
linkRegex = regexp.MustCompile(`- \[\x60(.+?)\x60\]\((.+?)\)`) | ||
detailsRegex = regexp.MustCompile(`</details>`) | ||
) | ||
|
||
func parseExamples() { | ||
file, err := ioutil.ReadFile("site/fields/index.html") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
file = headerRegex.ReplaceAll(file, []byte(newHeader)) | ||
file = headerAltRegex.ReplaceAll(file, []byte(newHeaderAlt)) | ||
file = linkRegex.ReplaceAll(file, []byte(newLink)) | ||
file = detailsRegex.ReplaceAll(file, []byte(newDetails)) | ||
|
||
err = ioutil.WriteFile("site/fields/index.html", file, 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |