4 Commits
v1 ... v2.0.0

Author SHA1 Message Date
James M. Greene
61fd3a3cc1 Merge pull request #19 from actions/no-trailing-slashes
[BREAKING] Remove the trailing slash from `base_url` and `base_path` outputs
2022-08-19 09:27:06 -05:00
James M. Greene
0ec542a837 Update distributables 2022-08-18 18:08:52 -05:00
James M. Greene
3a90973fd3 Use local module for removing trailing slash to reduce duplication 2022-08-18 18:08:30 -05:00
James M. Greene
dc5b850bfd breaking: Remove trailing slash from base_url and base_path outputs 2022-08-18 18:08:30 -05:00
7 changed files with 42 additions and 25 deletions

View File

@@ -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 ""'

28
dist/index.js vendored
View File

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

View File

@@ -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', '')
}) })
}) })

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 core = require('@actions/core')
const { ConfigParser } = require('./config-parser') 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, // 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 // optional configuration file path, and a Pages path value to inject
@@ -20,9 +21,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
} }
case 'next': case 'next':
// Next does not want a trailing slash // Next does not want a trailing slash
if (path.endsWith('/')) { path = removeTrailingSlash(path)
path = path.slice(0, -1)
}
return { return {
configurationFile: generatorConfigFile || './next.config.js', configurationFile: generatorConfigFile || './next.config.js',
@@ -47,9 +46,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
} }
case 'sveltekit': case 'sveltekit':
// SvelteKit does not want a trailing slash // SvelteKit does not want a trailing slash
if (path.endsWith('/')) { path = removeTrailingSlash(path)
path = path.slice(0, -1)
}
return { return {
configurationFile: generatorConfigFile || './svelte.config.js', configurationFile: generatorConfigFile || './svelte.config.js',