11 Commits

Author SHA1 Message Date
James M. Greene
45efe60937 Apply consistent spacing and use of single quotes 2022-09-11 10:23:22 -05:00
James M. Greene
35c001ded6 Dereference as 'path'
This minimizes the changes to the codebase, as well as slightly clarifying that its value may not remain the same as the 'pathname'
2022-09-11 10:23:22 -05:00
James M. Greene
27457957e6 Merge pull request #21 from AndrewLester/ssg-origin
Use GitHub Pages site origin for setting up SSG configs
2022-09-11 10:21:18 -05:00
AndrewLester
7ec0edaa8e Fix prepare output 2022-08-19 15:10:01 -05:00
AndrewLester
d48340abcd Use GitHub Pages site origin for setting up SSG configs 2022-08-19 14:33:39 -05:00
James M. Greene
f53b57ff56 Merge pull request #20 from actions/update-major-on-full-releases
Update major version only on full releases
2022-08-19 13:21:44 -05:00
James M. Greene
6d1d650751 Update major version only on full releases 2022-08-19 12:44:16 -05:00
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
30 changed files with 183 additions and 172 deletions

View File

@@ -1,7 +1,7 @@
name: Release name: Release
on: on:
release: release:
types: [published] types: [released]
workflow_dispatch: workflow_dispatch:
inputs: inputs:
TAG_NAME: TAG_NAME:

View File

@@ -2,7 +2,7 @@
A GitHub Action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as [starter workflows][starter-workflows]. A GitHub Action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as [starter workflows][starter-workflows].
See [`set-pages-path.js`](src/set-pages-path.js) for more details on how we configure static site generators to work "out of the box" with GitHub Pages. See [`set-pages-config.js`](src/set-pages-config.js) for more details on how we configure static site generators to work "out of the box" with GitHub Pages.
# Usage # Usage

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

58
dist/index.js vendored
View File

@@ -15438,7 +15438,7 @@ class ConfigParser {
throw 'Could not find a configuration object in the configuration file' throw 'Could not find a configuration object in the configuration file'
} }
// A property may be nested in the configuration file. Split the property name with `.` // A property may be nested in the configuration file. Split the property name with '.'
// then walk the configuration object one property at a time. // then walk the configuration object one property at a time.
var depth = 0 var depth = 0
const properties = propertyName.split('.') const properties = propertyName.split('.')
@@ -15519,7 +15519,7 @@ class ConfigParser {
} }
// Logging // Logging
core.info(`Injection successful, new configuration:`) core.info('Injection successful, new configuration:')
core.info(this.configuration) core.info(this.configuration)
// Finally write the new configuration in the file // Finally write the new configuration in the file
@@ -15571,12 +15571,17 @@ 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
@@ -15584,15 +15589,28 @@ module.exports = outputPagesBaseUrl
/***/ }), /***/ }),
/***/ 4770: /***/ 9255:
/***/ ((module) => {
module.exports = function removeTrailingSlash(str) {
return str.endsWith('/') ? str.slice(0, -1) : str
}
/***/ }),
/***/ 6310:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
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 siteUrl value to inject
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path }) { function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
let { pathname: path, origin } = siteUrl
switch (staticSiteGenerator) { switch (staticSiteGenerator) {
case 'nuxt': case 'nuxt':
return { return {
@@ -15609,9 +15627,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',
@@ -15631,21 +15647,23 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
blankConfigurationFile: __nccwpck_require__.ab + "gatsby.js", blankConfigurationFile: __nccwpck_require__.ab + "gatsby.js",
properties: { properties: {
// Configure a path prefix // Configure a path prefix
pathPrefix: path pathPrefix: path,
// Configure a site url
'siteMetadata.siteUrl': origin
} }
} }
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',
blankConfigurationFile: __nccwpck_require__.ab + "sveltekit.js", blankConfigurationFile: __nccwpck_require__.ab + "sveltekit.js",
properties: { properties: {
// Configure a base path // Configure a base path
'kit.paths.base': path 'kit.paths.base': path,
// Configure a prerender origin
'kit.prerender.origin': origin
} }
} }
default: default:
@@ -15654,10 +15672,10 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
} }
// Inject Pages configuration in a given static site generator's configuration file // Inject Pages configuration in a given static site generator's configuration file
function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) { function setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
try { try {
// Parse the configuration file and try to inject the Pages configuration in it // Parse the configuration file and try to inject the Pages configuration in it
const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path }) const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl })
new ConfigParser(settings).injectAll() new ConfigParser(settings).injectAll()
} catch (error) { } catch (error) {
// Logging // Logging
@@ -15668,7 +15686,7 @@ function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) {
} }
} }
module.exports = { getConfigParserSettings, setPagesPath } module.exports = { getConfigParserSettings, setPagesConfig }
/***/ }), /***/ }),
@@ -17163,7 +17181,7 @@ const core = __nccwpck_require__(2186)
const { getContext } = __nccwpck_require__(1319) const { getContext } = __nccwpck_require__(1319)
const { findOrCreatePagesSite } = __nccwpck_require__(9432) const { findOrCreatePagesSite } = __nccwpck_require__(9432)
const { setPagesPath } = __nccwpck_require__(4770) const { setPagesConfig } = __nccwpck_require__(6310)
const outputPagesBaseUrl = __nccwpck_require__(7527) const outputPagesBaseUrl = __nccwpck_require__(7527)
async function main() { async function main() {
@@ -17174,7 +17192,7 @@ async function main() {
const siteUrl = new URL(pageObject.html_url) const siteUrl = new URL(pageObject.html_url)
if (staticSiteGenerator) { if (staticSiteGenerator) {
setPagesPath({ staticSiteGenerator, generatorConfigFile, path: siteUrl.pathname }) setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl })
} }
outputPagesBaseUrl(siteUrl) outputPagesBaseUrl(siteUrl)
core.exportVariable('GITHUB_PAGES', 'true') core.exportVariable('GITHUB_PAGES', 'true')

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -184,7 +184,7 @@ class ConfigParser {
throw 'Could not find a configuration object in the configuration file' throw 'Could not find a configuration object in the configuration file'
} }
// A property may be nested in the configuration file. Split the property name with `.` // A property may be nested in the configuration file. Split the property name with '.'
// then walk the configuration object one property at a time. // then walk the configuration object one property at a time.
var depth = 0 var depth = 0
const properties = propertyName.split('.') const properties = propertyName.split('.')
@@ -265,7 +265,7 @@ class ConfigParser {
} }
// Logging // Logging
core.info(`Injection successful, new configuration:`) core.info('Injection successful, new configuration:')
core.info(this.configuration) core.info(this.configuration)
// Finally write the new configuration in the file // Finally write the new configuration in the file

View File

@@ -14,79 +14,79 @@ const cases = [
// //
{ {
property: 'property', property: 'property',
source: `export default {}`, source: 'export default {}',
expected: `export default { property: "value" }` expected: 'export default { property: "value" }'
}, },
{ {
property: 'property', property: 'property',
source: `export default { property: 0 }`, // property exists and is a number source: 'export default { property: 0 }', // property exists and is a number
expected: `export default { property: "value" }` expected: 'export default { property: "value" }'
}, },
{ {
property: 'property', property: 'property',
source: `export default { property: false }`, // property exists and is a boolean source: 'export default { property: false }', // property exists and is a boolean
expected: `export default { property: "value" }` expected: 'export default { property: "value" }'
}, },
{ {
property: 'property', property: 'property',
source: `export default { property: "test" }`, // property exists and is a string source: 'export default { property: "test" }', // property exists and is a string
expected: `export default { property: "value" }` expected: 'export default { property: "value" }'
}, },
{ {
property: 'property', property: 'property',
source: `export default { property: [1,2] }`, // property exists and is an array source: 'export default { property: [1,2] }', // property exists and is an array
expected: `export default { property: "value" }` expected: 'export default { property: "value" }'
}, },
{ {
property: 'property', property: 'property',
source: `export default { property: null }`, // property exists and is null source: 'export default { property: null }', // property exists and is null
expected: `export default { property: "value" }` expected: 'export default { property: "value" }'
}, },
{ {
property: 'property', property: 'property',
source: `export default { property: {}}`, // property exists and is an object source: 'export default { property: { } }', // property exists and is an object
expected: `export default { property: "value" }` expected: 'export default { property: "value" }'
}, },
// Deep properties (injection 1) // Deep properties (injection 1)
{ {
property: 'property.b.c', property: 'property.b.c',
source: `export default {}`, source: 'export default {}',
expected: `export default { property: { b: { c: "value" }}}` expected: 'export default { property: { b: { c: "value" } } }'
}, },
{ {
property: 'property.b.c', property: 'property.b.c',
source: `export default { property: 0 }`, // property exists and is a number source: 'export default { property: 0 }', // property exists and is a number
expected: `export default { property: { b: { c: "value" }}}` expected: 'export default { property: { b: { c: "value" } } }'
}, },
{ {
property: 'property.b.c', property: 'property.b.c',
source: `export default { property: {}}`, // property exists and is an object source: 'export default { property: { } }', // property exists and is an object
expected: `export default { property: { b: { c: "value" }}}` expected: 'export default { property: { b: { c: "value" } } }'
}, },
// Deep properties (injection 2) // Deep properties (injection 2)
{ {
property: 'property.b.c', property: 'property.b.c',
source: `export default { property: { b: 0 }}`, // property exists and is a number source: 'export default { property: { b: 0 } }', // property exists and is a number
expected: `export default { property: { b: { c: "value" }}}` expected: 'export default { property: { b: { c: "value" } } }'
}, },
{ {
property: 'property.b.c', property: 'property.b.c',
source: `export default { property: { b: {}}}`, // property exists and is an object source: 'export default { property: { b: { } } }', // property exists and is an object
expected: `export default { property: { b: { c: "value" }}}` expected: 'export default { property: { b: { c: "value" } } }'
}, },
{ {
property: 'property.b.c', property: 'property.b.c',
source: `export default { property: { b: { hello: 123}}}`, // property exists and is a non-empty object source: 'export default { property: { b: { hello: 123 } } }', // property exists and is a non-empty object
expected: `export default { property: { b: { c: "value", hello: 123 }}}` expected: 'export default { property: { b: { c: "value", hello: 123 } } }'
}, },
// Deep properties (existing properties) // Deep properties (existing properties)
{ {
property: 'a1.a2', property: 'a1.a2',
source: `export default { a2: false, a1: { a3: [12]}}`, // property exists and is a non-empty object source: 'export default { a2: false, a1: { a3: [12] } }', // property exists and is a non-empty object
expected: `export default { a2: false, a1: { a2: "value", a3: [12]}}` expected: 'export default { a2: false, a1: { a2: "value", a3: [12] } }'
}, },
// //
@@ -94,23 +94,23 @@ const cases = [
// //
{ {
property: 'property', property: 'property',
source: `const config = {}; export default config`, source: 'const config = {}; export default config',
expected: `const config = { property: "value"}; export default config` expected: 'const config = { property: "value"}; export default config'
}, },
{ {
property: 'property', property: 'property',
source: `var config = {}; export default config`, source: 'var config = {}; export default config',
expected: `var config = { property: "value"}; export default config` expected: 'var config = { property: "value"}; export default config'
}, },
{ {
property: 'a.b.c', property: 'a.b.c',
source: `var config = {}; export default config`, source: 'var config = {}; export default config',
expected: `var config = { a: { b: { c: "value"}}}; export default config` expected: 'var config = { a: { b: { c: "value" } } }; export default config'
}, },
{ {
property: 'a.b.c', property: 'a.b.c',
source: `var config = { a: { b: [], c: "hello"}}; export default config`, source: 'var config = { a: { b: [], c: "hello" } }; export default config',
expected: `var config = { a: { b: { c: "value"}, c: "hello"}}; export default config` expected: 'var config = { a: { b: { c: "value"}, c: "hello" } }; export default config'
}, },
// //
@@ -118,18 +118,18 @@ const cases = [
// //
{ {
property: 'property', property: 'property',
source: `module.exports = {}`, source: 'module.exports = {}',
expected: `module.exports = { property: "value"}` expected: 'module.exports = { property: "value"}'
}, },
{ {
property: 'property', property: 'property',
source: `module.exports = { p1: 0}`, source: 'module.exports = { p1: 0}',
expected: `module.exports = { property: "value", p1: 0}` expected: 'module.exports = { property: "value", p1: 0}'
}, },
{ {
property: 'a.b.c', property: 'a.b.c',
source: `module.exports = { p1: 0}`, source: 'module.exports = { p1: 0}',
expected: `module.exports = { a: { b: { c: "value" }}, p1: 0}` expected: 'module.exports = { a: { b: { c: "value" } }, p1: 0}'
}, },
// //
@@ -137,23 +137,23 @@ const cases = [
// //
{ {
property: 'property', property: 'property',
source: `const config = {}; module.exports = config`, source: 'const config = {}; module.exports = config',
expected: `const config = { property: "value"}; module.exports = config` expected: 'const config = { property: "value"}; module.exports = config'
}, },
{ {
property: 'property', property: 'property',
source: `var config = {}; module.exports = config`, source: 'var config = {}; module.exports = config',
expected: `var config = { property: "value"}; module.exports = config` expected: 'var config = { property: "value"}; module.exports = config'
}, },
{ {
property: 'a.b.c', property: 'a.b.c',
source: `var config = {}; module.exports = config`, source: 'var config = {}; module.exports = config',
expected: `var config = { a: { b: { c: "value"}}}; module.exports = config` expected: 'var config = { a: { b: { c: "value" } } }; module.exports = config'
}, },
{ {
property: 'a.b.c', property: 'a.b.c',
source: `var config = { a: { b: [], c: "hello"}}; module.exports = config`, source: 'var config = { a: { b: [], c: "hello" } }; module.exports = config',
expected: `var config = { a: { b: { c: "value"}, c: "hello"}}; module.exports = config` expected: 'var config = { a: { b: { c: "value"}, c: "hello" } }; module.exports = config'
} }
] ]

View File

@@ -1,2 +1,2 @@
// Default Pages configuration for Gatsby // Default Pages configuration for Gatsby
module.exports = { pathPrefix: '/docs/' } module.exports = { siteMetadata: { siteUrl: 'https://configure-pages.github.io' }, pathPrefix: '/docs/' }

View File

@@ -1,7 +1,6 @@
module.exports = { module.exports = {
siteMetadata: { siteMetadata: {
title: `My Gatsby Site`, title: 'My Gatsby Site'
siteUrl: `https://www.yourdomain.tld`,
}, },
plugins: [], plugins: []
} }

View File

@@ -1,8 +1,8 @@
module.exports = { module.exports = {
pathPrefix: "/docs/", pathPrefix: '/docs/',
siteMetadata: { siteMetadata: {
title: `My Gatsby Site`, siteUrl: 'https://configure-pages.github.io',
siteUrl: `https://www.yourdomain.tld`, title: 'My Gatsby Site'
}, },
plugins: [], plugins: []
} }

View File

@@ -1,8 +1,8 @@
module.exports = { module.exports = {
pathPrefix: '/docs/', pathPrefix: '/docs/',
siteMetadata: { siteMetadata: {
title: `My Gatsby Site`, siteUrl: 'https://configure-pages.github.io',
siteUrl: `https://www.yourdomain.tld` title: 'My Gatsby Site'
}, },
plugins: [] plugins: []
} }

View File

@@ -1,8 +1,8 @@
export default { export default {
pathPrefix: "/docs/", pathPrefix: '/docs/',
siteMetadata: { siteMetadata: {
title: `My Gatsby Site`, siteUrl: 'https://configure-pages.github.io',
siteUrl: `https://www.yourdomain.tld`, title: 'My Gatsby Site'
}, },
plugins: [], plugins: []
} }

View File

@@ -1,7 +1,6 @@
module.exports = { module.exports = {
siteMetadata: { siteMetadata: {
title: `My Gatsby Site`, title: 'My Gatsby Site'
siteUrl: `https://www.yourdomain.tld`
}, },
plugins: [] plugins: []
} }

View File

@@ -1,7 +1,6 @@
export default { export default {
siteMetadata: { siteMetadata: {
title: `My Gatsby Site`, title: 'My Gatsby Site'
siteUrl: `https://www.yourdomain.tld`,
}, },
plugins: [], plugins: []
} }

View File

@@ -20,25 +20,20 @@ module.exports = {
}, },
// Global CSS: https://go.nuxtjs.dev/config-css // Global CSS: https://go.nuxtjs.dev/config-css
css: [ css: [],
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [ plugins: [],
],
// Auto import components: https://go.nuxtjs.dev/config-components // Auto import components: https://go.nuxtjs.dev/config-components
components: true, components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [ buildModules: [],
],
// Modules: https://go.nuxtjs.dev/config-modules // Modules: https://go.nuxtjs.dev/config-modules
modules: [ modules: [],
],
// Build Configuration: https://go.nuxtjs.dev/config-build // Build Configuration: https://go.nuxtjs.dev/config-build
build: { build: {}
}
} }

View File

@@ -1,7 +1,7 @@
module.exports = { module.exports = {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
target: 'static', target: 'static',
router: { base: "/docs/" }, router: { base: '/docs/' },
ssr: false, ssr: false,
// Global page headers: https://go.nuxtjs.dev/config-head // Global page headers: https://go.nuxtjs.dev/config-head
@@ -22,25 +22,20 @@ module.exports = {
}, },
// Global CSS: https://go.nuxtjs.dev/config-css // Global CSS: https://go.nuxtjs.dev/config-css
css: [ css: [],
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [ plugins: [],
],
// Auto import components: https://go.nuxtjs.dev/config-components // Auto import components: https://go.nuxtjs.dev/config-components
components: true, components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [ buildModules: [],
],
// Modules: https://go.nuxtjs.dev/config-modules // Modules: https://go.nuxtjs.dev/config-modules
modules: [ modules: [],
],
// Build Configuration: https://go.nuxtjs.dev/config-build // Build Configuration: https://go.nuxtjs.dev/config-build
build: { build: {}
}
} }

View File

@@ -1,7 +1,7 @@
export default { export default {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
target: 'static', target: 'static',
router: { base: "/docs/" }, router: { base: '/docs/' },
ssr: false, ssr: false,
// Global page headers: https://go.nuxtjs.dev/config-head // Global page headers: https://go.nuxtjs.dev/config-head
@@ -22,25 +22,20 @@ export default {
}, },
// Global CSS: https://go.nuxtjs.dev/config-css // Global CSS: https://go.nuxtjs.dev/config-css
css: [ css: [],
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [ plugins: [],
],
// Auto import components: https://go.nuxtjs.dev/config-components // Auto import components: https://go.nuxtjs.dev/config-components
components: true, components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [ buildModules: [],
],
// Modules: https://go.nuxtjs.dev/config-modules // Modules: https://go.nuxtjs.dev/config-modules
modules: [ modules: [],
],
// Build Configuration: https://go.nuxtjs.dev/config-build // Build Configuration: https://go.nuxtjs.dev/config-build
build: { build: {}
}
} }

View File

@@ -20,25 +20,20 @@ export default {
}, },
// Global CSS: https://go.nuxtjs.dev/config-css // Global CSS: https://go.nuxtjs.dev/config-css
css: [ css: [],
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [ plugins: [],
],
// Auto import components: https://go.nuxtjs.dev/config-components // Auto import components: https://go.nuxtjs.dev/config-components
components: true, components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [ buildModules: [],
],
// Modules: https://go.nuxtjs.dev/config-modules // Modules: https://go.nuxtjs.dev/config-modules
modules: [ modules: [],
],
// Build Configuration: https://go.nuxtjs.dev/config-build // Build Configuration: https://go.nuxtjs.dev/config-build
build: { build: {}
}
} }

View File

@@ -3,6 +3,7 @@ import adapter from '@sveltejs/adapter-auto'
export default { export default {
kit: { kit: {
prerender: { origin: 'https://configure-pages.github.io' },
paths: { base: '/docs' }, paths: { base: '/docs' },
adapter: adapter() adapter: adapter()
} }

View File

@@ -3,6 +3,7 @@ import adapter from '@sveltejs/adapter-auto'
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
kit: { kit: {
prerender: { origin: 'https://configure-pages.github.io' },
paths: { base: '/docs' }, paths: { base: '/docs' },
adapter: adapter() adapter: adapter()
} }

View File

@@ -4,7 +4,7 @@ const core = require('@actions/core')
const { getContext } = require('./context') const { getContext } = require('./context')
const { findOrCreatePagesSite } = require('./api-client') const { findOrCreatePagesSite } = require('./api-client')
const { setPagesPath } = require('./set-pages-path') const { setPagesConfig } = require('./set-pages-config')
const outputPagesBaseUrl = require('./output-pages-base-url') const outputPagesBaseUrl = require('./output-pages-base-url')
async function main() { async function main() {
@@ -15,7 +15,7 @@ async function main() {
const siteUrl = new URL(pageObject.html_url) const siteUrl = new URL(pageObject.html_url)
if (staticSiteGenerator) { if (staticSiteGenerator) {
setPagesPath({ staticSiteGenerator, generatorConfigFile, path: siteUrl.pathname }) setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl })
} }
outputPagesBaseUrl(siteUrl) outputPagesBaseUrl(siteUrl)
core.exportVariable('GITHUB_PAGES', 'true') core.exportVariable('GITHUB_PAGES', 'true')

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,9 +1,12 @@
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 siteUrl value to inject
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path }) { function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
let { pathname: path, origin } = siteUrl
switch (staticSiteGenerator) { switch (staticSiteGenerator) {
case 'nuxt': case 'nuxt':
return { return {
@@ -20,9 +23,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',
@@ -42,21 +43,23 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
blankConfigurationFile: `${__dirname}/blank-configurations/gatsby.js`, blankConfigurationFile: `${__dirname}/blank-configurations/gatsby.js`,
properties: { properties: {
// Configure a path prefix // Configure a path prefix
pathPrefix: path pathPrefix: path,
// Configure a site url
'siteMetadata.siteUrl': origin
} }
} }
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',
blankConfigurationFile: `${__dirname}/blank-configurations/sveltekit.js`, blankConfigurationFile: `${__dirname}/blank-configurations/sveltekit.js`,
properties: { properties: {
// Configure a base path // Configure a base path
'kit.paths.base': path 'kit.paths.base': path,
// Configure a prerender origin
'kit.prerender.origin': origin
} }
} }
default: default:
@@ -65,10 +68,10 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
} }
// Inject Pages configuration in a given static site generator's configuration file // Inject Pages configuration in a given static site generator's configuration file
function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) { function setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
try { try {
// Parse the configuration file and try to inject the Pages configuration in it // Parse the configuration file and try to inject the Pages configuration in it
const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path }) const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl })
new ConfigParser(settings).injectAll() new ConfigParser(settings).injectAll()
} catch (error) { } catch (error) {
// Logging // Logging
@@ -79,4 +82,4 @@ function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) {
} }
} }
module.exports = { getConfigParserSettings, setPagesPath } module.exports = { getConfigParserSettings, setPagesConfig }

View File

@@ -2,7 +2,7 @@ const fs = require('fs')
const path = require('path') const path = require('path')
const core = require('@actions/core') const core = require('@actions/core')
const { getConfigParserSettings } = require('./set-pages-path') const { getConfigParserSettings } = require('./set-pages-config')
const { ConfigParser } = require('./config-parser') const { ConfigParser } = require('./config-parser')
const { getTempFolder, compareFiles } = require('./test-helpers') const { getTempFolder, compareFiles } = require('./test-helpers')
@@ -32,6 +32,9 @@ describe('configParser', () => {
// Get fixture files, excluding expected results // Get fixture files, excluding expected results
const configurationFiles = fs.readdirSync(fixtureFolder).filter(filename => !filename.includes('.expected.')) const configurationFiles = fs.readdirSync(fixtureFolder).filter(filename => !filename.includes('.expected.'))
// Create test siteUrl
const siteUrl = new URL('https://configure-pages.github.io/docs/')
// Iterate over the fixtures, outputting to default configuration file path // Iterate over the fixtures, outputting to default configuration file path
const defaultFileExtension = '.js' const defaultFileExtension = '.js'
configurationFiles configurationFiles
@@ -48,7 +51,7 @@ describe('configParser', () => {
} }
// Get settings for the static site generator // Get settings for the static site generator
const settings = getConfigParserSettings({ staticSiteGenerator, path: '/docs/' }) const settings = getConfigParserSettings({ staticSiteGenerator, siteUrl })
// Update the settings // Update the settings
settings.configurationFile = fixtureTargetFile settings.configurationFile = fixtureTargetFile
// Do the injection // Do the injection
@@ -84,7 +87,7 @@ describe('configParser', () => {
const settings = getConfigParserSettings({ const settings = getConfigParserSettings({
staticSiteGenerator, staticSiteGenerator,
generatorConfigFile: fixtureTargetFile, generatorConfigFile: fixtureTargetFile,
path: '/docs/' siteUrl
}) })
// Do the injection // Do the injection