diff --git a/.github/workflows/test-reusable.yml b/.github/workflows/test-reusable.yml index b37d7ac..8dad614 100644 --- a/.github/workflows/test-reusable.yml +++ b/.github/workflows/test-reusable.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6669d4b..15f0a58 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/README.md b/README.md index 719e102..85f8266 100644 --- a/README.md +++ b/README.md @@ -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 can be a path ``` Will generate the following links: * `http:///abc` will redirect to `https://google.com` * `http:///def` will redirect to `https://yahoo.com` - * `http:///xyz` will redirect to `https://some-other-site.com` + * `http:///uvw/xyz` will redirect to `https://some-other-site.com`

@@ -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: @@ -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): @@ -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 ``` @@ -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 diff --git a/tests/test_gen_paths.bats b/tests/test_gen_paths.bats new file mode 100644 index 0000000..2170f13 --- /dev/null +++ b/tests/test_gen_paths.bats @@ -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 "" +## * 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" +} \ No newline at end of file