diff --git a/src/output-pages-base-url.js b/src/output-pages-base-url.js index 3ea0cc5..34a699c 100644 --- a/src/output-pages-base-url.js +++ b/src/output-pages-base-url.js @@ -1,11 +1,5 @@ const core = require('@actions/core') - -function removeTrailingSlash(str) { - if (str.endsWith('/')) { - str = str.slice(0, -1) - } - return str -} +const removeTrailingSlash = require('./remove-trailing-slash') function outputPagesBaseUrl(siteUrl) { // Many static site generators do not want the trailing slash, and it is much easier to add than remove in a workflow diff --git a/src/remove-trailing-slash.js b/src/remove-trailing-slash.js new file mode 100644 index 0000000..e625dc2 --- /dev/null +++ b/src/remove-trailing-slash.js @@ -0,0 +1,3 @@ +module.exports = function removeTrailingSlash(str) { + return str.endsWith('/') ? str.slice(0, -1) : str +} diff --git a/src/set-pages-path.js b/src/set-pages-path.js index c76f37b..b1b6c20 100644 --- a/src/set-pages-path.js +++ b/src/set-pages-path.js @@ -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',