mirror of
https://github.com/actions/configure-pages.git
synced 2025-12-08 16:16:09 +00:00
breaking: Remove trailing slash from base_url and base_path outputs
This commit is contained in:
@@ -21,10 +21,10 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
base_url:
|
base_url:
|
||||||
description: 'GitHub Pages site full base URL. Examples: "https://octocat.github.io/my-repo/", "https://octocat.github.io/", "https://www.example.com/"'
|
description: 'GitHub Pages site full base URL. Examples: "https://octocat.github.io/my-repo", "https://octocat.github.io", "https://www.example.com"'
|
||||||
origin:
|
origin:
|
||||||
description: 'GitHub Pages site origin. Examples: "https://octocat.github.io", "https://www.example.com"'
|
description: 'GitHub Pages site origin. Examples: "https://octocat.github.io", "https://www.example.com"'
|
||||||
host:
|
host:
|
||||||
description: 'GitHub Pages site host. Examples: "octocat.github.io", "www.example.com"'
|
description: 'GitHub Pages site host. Examples: "octocat.github.io", "www.example.com"'
|
||||||
base_path:
|
base_path:
|
||||||
description: 'GitHub Pages site full base path. Examples: "/my-repo/" or "/"'
|
description: 'GitHub Pages site full base path. Examples: "/my-repo" or ""'
|
||||||
|
|||||||
@@ -1,10 +1,21 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
|
|
||||||
|
function removeTrailingSlash(str) {
|
||||||
|
if (str.endsWith('/')) {
|
||||||
|
str = str.slice(0, -1)
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
function outputPagesBaseUrl(siteUrl) {
|
function outputPagesBaseUrl(siteUrl) {
|
||||||
core.setOutput('base_url', siteUrl.href)
|
// Many static site generators do not want the trailing slash, and it is much easier to add than remove in a workflow
|
||||||
|
const baseUrl = removeTrailingSlash(siteUrl.href)
|
||||||
|
const basePath = removeTrailingSlash(siteUrl.pathname)
|
||||||
|
|
||||||
|
core.setOutput('base_url', baseUrl)
|
||||||
core.setOutput('origin', siteUrl.origin)
|
core.setOutput('origin', siteUrl.origin)
|
||||||
core.setOutput('host', siteUrl.host)
|
core.setOutput('host', siteUrl.host)
|
||||||
core.setOutput('base_path', siteUrl.pathname)
|
core.setOutput('base_path', basePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = outputPagesBaseUrl
|
module.exports = outputPagesBaseUrl
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
|
|
||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', 'https://octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('gets expected outputs for project site', async () => {
|
it('gets expected outputs for project site', async () => {
|
||||||
@@ -34,10 +34,10 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
|
|
||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', 'https://octocat.github.io/my-repo')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/my-repo/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/my-repo')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('gets expected outputs for site with custom domain name', async () => {
|
it('gets expected outputs for site with custom domain name', async () => {
|
||||||
@@ -45,9 +45,9 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
|
|
||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', 'https://www.example.com')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://www.example.com')
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://www.example.com')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'www.example.com')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'www.example.com')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user