Skip to content

Commit

Permalink
fix: do not create garbage in examples nav bar (#652)
Browse files Browse the repository at this point in the history
* fix: do not create garbage in examples nav bar

* chore: uses same format that the produced by the generator
  • Loading branch information
mdelapenya committed Dec 5, 2022
1 parent b73d5c6 commit b7cdaad
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 68 deletions.
6 changes: 4 additions & 2 deletions examples/main.go
Expand Up @@ -145,11 +145,13 @@ func generate(example Example, rootDir string) error {

// make sure the index.md is the first element in the list of examples in the nav
examplesNav := make([]string, len(mkdocsExamplesNav)-1)
j := 0

for _, exampleNav := range mkdocsExamplesNav {
// filter out the index.md file
if !strings.HasSuffix("index.md", exampleNav) {
examplesNav = append(examplesNav, exampleNav)
if !strings.HasSuffix(exampleNav, "index.md") {
examplesNav[j] = exampleNav
j++
}
}

Expand Down
12 changes: 9 additions & 3 deletions examples/main_test.go
Expand Up @@ -68,6 +68,9 @@ func TestGenerate(t *testing.T) {
err = copyInitialConfig(t, rootTmp)
assert.Nil(t, err)

originalConfig, err := readMkdocsConfig(rootTmp)
assert.Nil(t, err)

example := Example{
Name: "foo",
Image: "docker.io/example/foo:latest",
Expand Down Expand Up @@ -109,7 +112,7 @@ func TestGenerate(t *testing.T) {
assertGoModContent(t, example, filepath.Join(generatedTemplatesDir, "go.mod"))
assertMakefileContent(t, example, filepath.Join(generatedTemplatesDir, "Makefile"))
assertToolsGoContent(t, example, filepath.Join(generatedTemplatesDir, "tools", "tools.go"))
assertMkdocsExamplesNav(t, example, rootTmp)
assertMkdocsExamplesNav(t, example, originalConfig, rootTmp)
}

// assert content example file in the docs
Expand Down Expand Up @@ -197,12 +200,15 @@ func assertMakefileContent(t *testing.T, example Example, makefile string) {
}

// assert content in the Examples nav from mkdocs.yml
func assertMkdocsExamplesNav(t *testing.T, example Example, rootDir string) {
func assertMkdocsExamplesNav(t *testing.T, example Example, originalConfig *MkDocsConfig, rootDir string) {
config, err := readMkdocsConfig(rootDir)
assert.Nil(t, err)

// the example should be in the nav
examples := config.Nav[3].Examples

assert.Equal(t, len(originalConfig.Nav[3].Examples)+1, len(examples))

// the example should be in the nav
found := false
for _, ex := range examples {
markdownExample := "examples/" + example.Lower() + ".md"
Expand Down
126 changes: 63 additions & 63 deletions mkdocs.yml
@@ -1,71 +1,71 @@
site_name: Testcontainers for Go
plugins:
- search
- codeinclude
- markdownextradata
- search
- codeinclude
- markdownextradata
theme:
name: 'material'
palette:
scheme: testcontainers
font:
text: Roboto
code: Roboto Mono
logo: 'logo.svg'
favicon: 'favicon.ico'
name: material
palette:
scheme: testcontainers
font:
text: Roboto
code: Roboto Mono
logo: logo.svg
favicon: favicon.ico
extra_css:
- 'css/extra.css'
repo_name: 'testcontainers-go'
repo_url: 'https://github.com/testcontainers/testcontainers-go'
- css/extra.css
repo_name: testcontainers-go
repo_url: https://github.com/testcontainers/testcontainers-go
markdown_extensions:
- admonition
- codehilite:
linenums: False
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.snippets
- admonition
- codehilite:
linenums: false
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.snippets
nav:
- Home: index.md
- Quickstart:
- quickstart/gotest.md
- Features:
- features/creating_container.md
- features/networking.md
- features/garbage_collector.md
- features/build_from_dockerfile.md
- features/docker_compose.md
- features/follow_logs.md
- features/override_container_command.md
- features/copy_file.md
- Wait Strategies:
- Introduction: features/wait/introduction.md
- Exec: features/wait/exec.md
- Exit: features/wait/exit.md
- Health: features/wait/health.md
- HostPort: features/wait/host_port.md
- HTTP: features/wait/http.md
- Log: features/wait/log.md
- Multi: features/wait/multi.md
- SQL: features/wait/sql.md
- Examples:
- examples/index.md
- examples/cockroachdb.md
- examples/datastore.md
- examples/firestore.md
- examples/nginx.md
- examples/redis.md
- examples/pubsub.md
- examples/pulsar.md
- examples/spanner.md
- examples/toxiproxy.md
- System Requirements:
- system_requirements/index.md
- system_requirements/using_colima.md
- system_requirements/using_podman.md
- Contributing:
- contributing.md
- contributing_docs.md
- Getting help: getting_help.md
- Home: index.md
- Quickstart:
- quickstart/gotest.md
- Features:
- features/creating_container.md
- features/networking.md
- features/garbage_collector.md
- features/build_from_dockerfile.md
- features/docker_compose.md
- features/follow_logs.md
- features/override_container_command.md
- features/copy_file.md
- Wait Strategies:
- Introduction: features/wait/introduction.md
- Exec: features/wait/exec.md
- Exit: features/wait/exit.md
- Health: features/wait/health.md
- HostPort: features/wait/host_port.md
- HTTP: features/wait/http.md
- Log: features/wait/log.md
- Multi: features/wait/multi.md
- SQL: features/wait/sql.md
- Examples:
- examples/index.md
- examples/cockroachdb.md
- examples/datastore.md
- examples/firestore.md
- examples/nginx.md
- examples/redis.md
- examples/pubsub.md
- examples/pulsar.md
- examples/spanner.md
- examples/toxiproxy.md
- System Requirements:
- system_requirements/index.md
- system_requirements/using_colima.md
- system_requirements/using_podman.md
- Contributing:
- contributing.md
- contributing_docs.md
- Getting help: getting_help.md
edit_uri: edit/main/docs/
extra:
latest_version: 0.16.0
latest_version: 0.16.0

0 comments on commit b7cdaad

Please sign in to comment.