mirror of
https://github.com/actions/configure-pages.git
synced 2025-12-08 16:16:09 +00:00
Use local module for removing trailing slash to reduce duplication
This commit is contained in:
@@ -1,11 +1,5 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
|
const removeTrailingSlash = require('./remove-trailing-slash')
|
||||||
function removeTrailingSlash(str) {
|
|
||||||
if (str.endsWith('/')) {
|
|
||||||
str = str.slice(0, -1)
|
|
||||||
}
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
|
|
||||||
function outputPagesBaseUrl(siteUrl) {
|
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
|
// Many static site generators do not want the trailing slash, and it is much easier to add than remove in a workflow
|
||||||
|
|||||||
3
src/remove-trailing-slash.js
Normal file
3
src/remove-trailing-slash.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function removeTrailingSlash(str) {
|
||||||
|
return str.endsWith('/') ? str.slice(0, -1) : str
|
||||||
|
}
|
||||||
@@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user