Skip to content

Commit

Permalink
fix: Fix links in fields doc (#3539)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 authored and alexec committed Jul 28, 2020
1 parent d2bd587 commit d53c883
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.x
- name: Setup Golang
uses: actions/setup-go@v1
with:
go-version: '1.13.12'
- name: build
run: |
pip install mkdocs==1.0.4 mkdocs_material==4.1.1
mkdocs build
make parse-examples
mkdir ./site/.circleci && echo '{version: 2, jobs: {build: {branches: {ignore: gh-pages}}}}' > ./site/.circleci/config.yml
- name: deploy
uses: peaceiris/actions-gh-pages@v2.5.0
env:
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./site
PUBLISH_DIR: ./site
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,7 @@ endif
.PHONY: check-version-warning
check-version-warning:
@if [[ "$(VERSION)" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then echo -n "It looks like you're trying to use a SemVer version, but have not prepended it with a "v" (such as "v$(VERSION)"). The "v" is required for our releases. Do you wish to continue anyway? [y/N]" && read ans && [ $${ans:-N} = y ]; fi

.PHONY: parse-examples
parse-examples:
go run -tags fields ./hack parseexamples
2 changes: 2 additions & 0 deletions hack/docgen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !fields

package main

import (
Expand Down
6 changes: 5 additions & 1 deletion hack/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import "os"
import (
"os"
)

func main() {
switch os.Args[1] {
Expand All @@ -14,6 +16,8 @@ func main() {
kubeifySwagger(os.Args[2], os.Args[3])
case "secondaryswaggergen":
secondarySwaggerGen()
case "parseexamples":
parseExamples()
default:
panic(os.Args[1])
}
Expand Down
7 changes: 7 additions & 0 deletions hack/null_docgen.go
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")
}
42 changes: 42 additions & 0 deletions hack/parse_examples.go
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)
}
}

0 comments on commit d53c883

Please sign in to comment.