Merge pull request #19 from actions/no-trailing-slashes

[BREAKING] Remove the trailing slash from `base_url` and `base_path` outputs
This commit is contained in:
James M. Greene
2022-08-19 09:27:06 -05:00
committed by GitHub
7 changed files with 42 additions and 25 deletions

View File

@@ -21,10 +21,10 @@ inputs:
required: false
outputs:
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:
description: 'GitHub Pages site origin. Examples: "https://octocat.github.io", "https://www.example.com"'
host:
description: 'GitHub Pages site host. Examples: "octocat.github.io", "www.example.com"'
base_path:
description: 'GitHub Pages site full base path. Examples: "/my-repo/" or "/"'
description: 'GitHub Pages site full base path. Examples: "/my-repo" or ""'

28
dist/index.js vendored
View File

@@ -15571,17 +15571,32 @@ module.exports = { getContext }
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
const core = __nccwpck_require__(2186)
const removeTrailingSlash = __nccwpck_require__(9255)
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('host', siteUrl.host)
core.setOutput('base_path', siteUrl.pathname)
core.setOutput('base_path', basePath)
}
module.exports = outputPagesBaseUrl
/***/ }),
/***/ 9255:
/***/ ((module) => {
module.exports = function removeTrailingSlash(str) {
return str.endsWith('/') ? str.slice(0, -1) : str
}
/***/ }),
/***/ 4770:
@@ -15589,6 +15604,7 @@ module.exports = outputPagesBaseUrl
const core = __nccwpck_require__(2186)
const { ConfigParser } = __nccwpck_require__(8395)
const removeTrailingSlash = __nccwpck_require__(9255)
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
// optional configuration file path, and a Pages path value to inject
@@ -15609,9 +15625,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
}
case 'next':
// Next does not want a trailing slash
if (path.endsWith('/')) {
path = path.slice(0, -1)
}
path = removeTrailingSlash(path)
return {
configurationFile: generatorConfigFile || './next.config.js',
@@ -15636,9 +15650,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
}
case 'sveltekit':
// SvelteKit does not want a trailing slash
if (path.endsWith('/')) {
path = path.slice(0, -1)
}
path = removeTrailingSlash(path)
return {
configurationFile: generatorConfigFile || './svelte.config.js',

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,10 +1,15 @@
const core = require('@actions/core')
const removeTrailingSlash = require('./remove-trailing-slash')
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('host', siteUrl.host)
core.setOutput('base_path', siteUrl.pathname)
core.setOutput('base_path', basePath)
}
module.exports = outputPagesBaseUrl

View File

@@ -23,10 +23,10 @@ describe('outputPagesBaseUrl', () => {
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('host', 'octocat.github.io')
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
expect(core.setOutput).toHaveBeenCalledWith('base_path', '')
})
it('gets expected outputs for project site', async () => {
@@ -34,10 +34,10 @@ describe('outputPagesBaseUrl', () => {
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('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 () => {
@@ -45,9 +45,9 @@ describe('outputPagesBaseUrl', () => {
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('host', 'www.example.com')
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
expect(core.setOutput).toHaveBeenCalledWith('base_path', '')
})
})

View File

@@ -0,0 +1,3 @@
module.exports = function removeTrailingSlash(str) {
return str.endsWith('/') ? str.slice(0, -1) : str
}

View File

@@ -1,5 +1,6 @@
const core = require('@actions/core')
const { ConfigParser } = require('./config-parser')
const removeTrailingSlash = require('./remove-trailing-slash')
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
// optional configuration file path, and a Pages path value to inject
@@ -20,9 +21,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
}
case 'next':
// Next does not want a trailing slash
if (path.endsWith('/')) {
path = path.slice(0, -1)
}
path = removeTrailingSlash(path)
return {
configurationFile: generatorConfigFile || './next.config.js',
@@ -47,9 +46,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
}
case 'sveltekit':
// SvelteKit does not want a trailing slash
if (path.endsWith('/')) {
path = path.slice(0, -1)
}
path = removeTrailingSlash(path)
return {
configurationFile: generatorConfigFile || './svelte.config.js',