breaking: Remove trailing slash from base_url and base_path outputs

This commit is contained in:
James M. Greene
2022-08-18 17:45:54 -05:00
parent 9a141972ca
commit dc5b850bfd
3 changed files with 21 additions and 10 deletions

View File

@@ -1,10 +1,21 @@
const core = require('@actions/core')
function removeTrailingSlash(str) {
if (str.endsWith('/')) {
str = str.slice(0, -1)
}
return str
}
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