Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests and update docs for key-path supports #9

Merged
merged 9 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
with:
urls_config: ${{ inputs.urls_config }}
default_redirect: ${{ inputs.default_redirect }}
- name: Show tree (_redirects)
run: tree -a _redirects
- name: Show tree (_site)
run: tree -a _site
- name: Post-Run
run: |
${{ inputs.post-run }}
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ jobs:
default_redirect: "Nothing to see!"
post-run: bats ./tests/test_gen.bats

test-generation-paths:
name: Generate Redirects (sub-paths)
uses: ./.github/workflows/test-reusable.yml
with:
pre-run: |
# Create a test urls config file
cat <<- EOF > urls_tests.yml
---
a/b/c/test-d: http://www.abcd.com
EOF
urls_config: urls_tests.yml
default_redirect: "Nothing to see!"
post-run: bats ./tests/test_gen_paths.bats

test-default-redirect-url:
name: Default (Redirect URL)
uses: ./.github/workflows/test-reusable.yml
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ See [How it works](#how-it-works).
---
abc: "https://google.com"
def: "https://yahoo.com"
xyz: "https://some-other-site.com"
uvw/xyz: "https://some-other-site.com" # The <key> can be a path
```

Will generate the following links:

* `http://<your site>/abc` will redirect to `https://google.com`
* `http://<your site>/def` will redirect to `https://yahoo.com`
* `http://<your site>/xyz` will redirect to `https://some-other-site.com`
* `http://<your site>/uvw/xyz` will redirect to `https://some-other-site.com`

</p>
</details>
Expand Down Expand Up @@ -131,11 +131,11 @@ Each URL to redirect is created by the action as an individual document defined
collections:
redirects:
output: true
permalink: /:name
permalink: /:path

```

*The above reads: "In `_redirects` (Jekyll's convention), generate one file per document (`output: true`) for which the final URL path will be `/:name` (i.e. name of the file, minus the extension)"*
*The above reads: "In `_redirects` (Jekyll's convention), generate one file per document (`output: true`) for which the final URL path will be `/:path` (i.e. path to the file, including the file, minus the extension)"*

For example, for an entry `link1: "https://google.com"` in `urls.yml`, the action would create `_redirect/link1.yml` as:

Expand Down Expand Up @@ -185,7 +185,7 @@ The generated file hierarchy is minimal. For instance, for a `urls.yml` that mig
---
abc: "https://google.com"
def: "https://yahoo.com"
xyz: "https://some-other-site.com"
uvw/xyz: "https://some-other-site.com"
```

The action will generate (if the action input `default_redirect` is set to a URL):
Expand All @@ -197,7 +197,8 @@ The action will generate (if the action input `default_redirect` is set to a URL
├── _redirects
│   ├── abc.md
│   ├── def.md
│   └── xyz.md
│   └── uvw
| └── xyz.md
└── index.md
```

Expand All @@ -210,7 +211,8 @@ And the GitHub Pages-hosted directory will look like:
├── def.html
├── index.html
├── redirects.json
└── xyx.html
└── uvw
└── xyx.html
```

## License
Expand Down
30 changes: 30 additions & 0 deletions tests/test_gen_paths.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
setup() {
# Create expected Jekyll files:
# temp-d.md
cat <<- EOF > temp-d.md
---
redirect_to: http://www.abcd.com
---
EOF
}

## Check if the Action
## * Generated the proper Markdown file
## * Generated the proper Markdown content

@test "a/b/c/temp-d.md should be generated" {
test -f _redirects/a/b/c/test-d.md
diff _redirects/a/b/c/test-d.md temp-d.md
}

## Check if Jekyll:
## * Generated the proper html file
## * Generated the proper html content
## * Contains "<!DOCTYPE html>"
## * Contains the URL redirect

@test "test-d.html should be generated" {
test -f _site/a/b/c/test-d.html
cat _site/a/b/c/test-d.html | grep "<\!DOCTYPE html>"
cat _site/a/b/c/test-d.html | grep "http://www.abcd.com"
}
Loading