Skip to content

Commit

Permalink
Use local module for removing trailing slash to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
James M. Greene authored and James M. Greene committed Aug 18, 2022
1 parent dc5b850 commit 3a90973
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
8 changes: 1 addition & 7 deletions src/output-pages-base-url.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/remove-trailing-slash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function removeTrailingSlash(str) {
return str.endsWith('/') ? str.slice(0, -1) : str
}
9 changes: 3 additions & 6 deletions src/set-pages-path.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 3a90973

Please sign in to comment.