mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 10:04:52 +00:00
Merge pull request #21 from AndrewLester/ssg-origin
Use GitHub Pages site origin for setting up SSG configs
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
34
dist/index.js
vendored
34
dist/index.js
vendored
@@ -15599,7 +15599,7 @@ module.exports = function removeTrailingSlash(str) {
|
|||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 4770:
|
/***/ 6310:
|
||||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
@@ -15607,8 +15607,10 @@ const { ConfigParser } = __nccwpck_require__(8395)
|
|||||||
const removeTrailingSlash = __nccwpck_require__(9255)
|
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, origin } = siteUrl
|
||||||
|
|
||||||
switch (staticSiteGenerator) {
|
switch (staticSiteGenerator) {
|
||||||
case 'nuxt':
|
case 'nuxt':
|
||||||
return {
|
return {
|
||||||
@@ -15616,7 +15618,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
|||||||
blankConfigurationFile: __nccwpck_require__.ab + "nuxt.js",
|
blankConfigurationFile: __nccwpck_require__.ab + "nuxt.js",
|
||||||
properties: {
|
properties: {
|
||||||
// Configure a base path on the router
|
// Configure a base path on the router
|
||||||
'router.base': path,
|
'router.base': pathname,
|
||||||
|
|
||||||
// Set the target to static too
|
// Set the target to static too
|
||||||
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
|
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
|
||||||
@@ -15625,14 +15627,14 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
|||||||
}
|
}
|
||||||
case 'next':
|
case 'next':
|
||||||
// Next does not want a trailing slash
|
// Next does not want a trailing slash
|
||||||
path = removeTrailingSlash(path)
|
pathname = removeTrailingSlash(pathname)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configurationFile: generatorConfigFile || './next.config.js',
|
configurationFile: generatorConfigFile || './next.config.js',
|
||||||
blankConfigurationFile: __nccwpck_require__.ab + "next.js",
|
blankConfigurationFile: __nccwpck_require__.ab + "next.js",
|
||||||
properties: {
|
properties: {
|
||||||
// Configure a base path
|
// Configure a base path
|
||||||
basePath: path,
|
basePath: pathname,
|
||||||
|
|
||||||
// Disable server side image optimization too
|
// Disable server side image optimization too
|
||||||
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
||||||
@@ -15645,19 +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: pathname,
|
||||||
|
// 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
|
||||||
path = removeTrailingSlash(path)
|
pathname = removeTrailingSlash(pathname)
|
||||||
|
|
||||||
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': pathname,
|
||||||
|
// Configure a prerender origin
|
||||||
|
'kit.prerender.origin': origin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -15666,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
|
||||||
@@ -15680,7 +15686,7 @@ function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getConfigParserSettings, setPagesPath }
|
module.exports = { getConfigParserSettings, setPagesConfig }
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -17175,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() {
|
||||||
@@ -17186,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
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -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/' }
|
||||||
|
|||||||
@@ -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: []
|
||||||
}
|
}
|
||||||
@@ -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: []
|
||||||
}
|
}
|
||||||
@@ -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: []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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: []
|
||||||
}
|
}
|
||||||
@@ -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: []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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: []
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ const { ConfigParser } = require('./config-parser')
|
|||||||
const removeTrailingSlash = require('./remove-trailing-slash')
|
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, origin } = siteUrl
|
||||||
|
|
||||||
switch (staticSiteGenerator) {
|
switch (staticSiteGenerator) {
|
||||||
case 'nuxt':
|
case 'nuxt':
|
||||||
return {
|
return {
|
||||||
@@ -12,7 +14,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
|||||||
blankConfigurationFile: `${__dirname}/blank-configurations/nuxt.js`,
|
blankConfigurationFile: `${__dirname}/blank-configurations/nuxt.js`,
|
||||||
properties: {
|
properties: {
|
||||||
// Configure a base path on the router
|
// Configure a base path on the router
|
||||||
'router.base': path,
|
'router.base': pathname,
|
||||||
|
|
||||||
// Set the target to static too
|
// Set the target to static too
|
||||||
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
|
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
|
||||||
@@ -21,14 +23,14 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
|||||||
}
|
}
|
||||||
case 'next':
|
case 'next':
|
||||||
// Next does not want a trailing slash
|
// Next does not want a trailing slash
|
||||||
path = removeTrailingSlash(path)
|
pathname = removeTrailingSlash(pathname)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configurationFile: generatorConfigFile || './next.config.js',
|
configurationFile: generatorConfigFile || './next.config.js',
|
||||||
blankConfigurationFile: `${__dirname}/blank-configurations/next.js`,
|
blankConfigurationFile: `${__dirname}/blank-configurations/next.js`,
|
||||||
properties: {
|
properties: {
|
||||||
// Configure a base path
|
// Configure a base path
|
||||||
basePath: path,
|
basePath: pathname,
|
||||||
|
|
||||||
// Disable server side image optimization too
|
// Disable server side image optimization too
|
||||||
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
||||||
@@ -41,19 +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: pathname,
|
||||||
|
// 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
|
||||||
path = removeTrailingSlash(path)
|
pathname = removeTrailingSlash(pathname)
|
||||||
|
|
||||||
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': pathname,
|
||||||
|
// Configure a prerender origin
|
||||||
|
'kit.prerender.origin': origin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -62,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
|
||||||
@@ -76,4 +82,4 @@ function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getConfigParserSettings, setPagesPath }
|
module.exports = { getConfigParserSettings, setPagesConfig }
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user