mirror of
https://github.com/actions/configure-pages.git
synced 2025-12-08 16:16:09 +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].
|
||||
|
||||
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
|
||||
|
||||
|
||||
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__) => {
|
||||
|
||||
const core = __nccwpck_require__(2186)
|
||||
@@ -15607,8 +15607,10 @@ 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,
|
||||
// optional configuration file path, and a Pages path value to inject
|
||||
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path }) {
|
||||
// optional configuration file path, and a Pages siteUrl value to inject
|
||||
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
||||
let { pathname, origin } = siteUrl
|
||||
|
||||
switch (staticSiteGenerator) {
|
||||
case 'nuxt':
|
||||
return {
|
||||
@@ -15616,7 +15618,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
blankConfigurationFile: __nccwpck_require__.ab + "nuxt.js",
|
||||
properties: {
|
||||
// Configure a base path on the router
|
||||
'router.base': path,
|
||||
'router.base': pathname,
|
||||
|
||||
// Set the target to static too
|
||||
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
|
||||
@@ -15625,14 +15627,14 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
}
|
||||
case 'next':
|
||||
// Next does not want a trailing slash
|
||||
path = removeTrailingSlash(path)
|
||||
pathname = removeTrailingSlash(pathname)
|
||||
|
||||
return {
|
||||
configurationFile: generatorConfigFile || './next.config.js',
|
||||
blankConfigurationFile: __nccwpck_require__.ab + "next.js",
|
||||
properties: {
|
||||
// Configure a base path
|
||||
basePath: path,
|
||||
basePath: pathname,
|
||||
|
||||
// Disable server side image optimization too
|
||||
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
||||
@@ -15645,19 +15647,23 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
blankConfigurationFile: __nccwpck_require__.ab + "gatsby.js",
|
||||
properties: {
|
||||
// Configure a path prefix
|
||||
pathPrefix: path
|
||||
pathPrefix: pathname,
|
||||
// Configure a site url
|
||||
'siteMetadata.siteUrl': origin
|
||||
}
|
||||
}
|
||||
case 'sveltekit':
|
||||
// SvelteKit does not want a trailing slash
|
||||
path = removeTrailingSlash(path)
|
||||
pathname = removeTrailingSlash(pathname)
|
||||
|
||||
return {
|
||||
configurationFile: generatorConfigFile || './svelte.config.js',
|
||||
blankConfigurationFile: __nccwpck_require__.ab + "sveltekit.js",
|
||||
properties: {
|
||||
// Configure a base path
|
||||
'kit.paths.base': path
|
||||
'kit.paths.base': pathname,
|
||||
// Configure a prerender origin
|
||||
'kit.prerender.origin': origin
|
||||
}
|
||||
}
|
||||
default:
|
||||
@@ -15666,10 +15672,10 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
}
|
||||
|
||||
// Inject Pages configuration in a given static site generator's configuration file
|
||||
function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) {
|
||||
function setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
||||
try {
|
||||
// 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()
|
||||
} catch (error) {
|
||||
// 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 { findOrCreatePagesSite } = __nccwpck_require__(9432)
|
||||
const { setPagesPath } = __nccwpck_require__(4770)
|
||||
const { setPagesConfig } = __nccwpck_require__(6310)
|
||||
const outputPagesBaseUrl = __nccwpck_require__(7527)
|
||||
|
||||
async function main() {
|
||||
@@ -17186,7 +17192,7 @@ async function main() {
|
||||
const siteUrl = new URL(pageObject.html_url)
|
||||
|
||||
if (staticSiteGenerator) {
|
||||
setPagesPath({ staticSiteGenerator, generatorConfigFile, path: siteUrl.pathname })
|
||||
setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl })
|
||||
}
|
||||
outputPagesBaseUrl(siteUrl)
|
||||
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
|
||||
module.exports = { pathPrefix: '/docs/' }
|
||||
module.exports = { siteMetadata: { siteUrl: 'https://configure-pages.github.io' }, pathPrefix: '/docs/' }
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
module.exports = {
|
||||
siteMetadata: {
|
||||
title: `My Gatsby Site`,
|
||||
siteUrl: `https://www.yourdomain.tld`,
|
||||
title: `My Gatsby Site`
|
||||
},
|
||||
plugins: [],
|
||||
plugins: []
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
module.exports = {
|
||||
pathPrefix: "/docs/",
|
||||
pathPrefix: '/docs/',
|
||||
siteMetadata: {
|
||||
title: `My Gatsby Site`,
|
||||
siteUrl: `https://www.yourdomain.tld`,
|
||||
siteUrl: 'https://configure-pages.github.io',
|
||||
title: `My Gatsby Site`
|
||||
},
|
||||
plugins: [],
|
||||
plugins: []
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
module.exports = {
|
||||
pathPrefix: '/docs/',
|
||||
siteMetadata: {
|
||||
title: `My Gatsby Site`,
|
||||
siteUrl: `https://www.yourdomain.tld`
|
||||
siteUrl: 'https://configure-pages.github.io',
|
||||
title: `My Gatsby Site`
|
||||
},
|
||||
plugins: []
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export default {
|
||||
pathPrefix: "/docs/",
|
||||
pathPrefix: '/docs/',
|
||||
siteMetadata: {
|
||||
title: `My Gatsby Site`,
|
||||
siteUrl: `https://www.yourdomain.tld`,
|
||||
siteUrl: 'https://configure-pages.github.io',
|
||||
title: `My Gatsby Site`
|
||||
},
|
||||
plugins: [],
|
||||
plugins: []
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
module.exports = {
|
||||
siteMetadata: {
|
||||
title: `My Gatsby Site`,
|
||||
siteUrl: `https://www.yourdomain.tld`
|
||||
title: `My Gatsby Site`
|
||||
},
|
||||
plugins: []
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
export default {
|
||||
siteMetadata: {
|
||||
title: `My Gatsby Site`,
|
||||
siteUrl: `https://www.yourdomain.tld`,
|
||||
title: `My Gatsby Site`
|
||||
},
|
||||
plugins: [],
|
||||
plugins: []
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import adapter from '@sveltejs/adapter-auto'
|
||||
|
||||
export default {
|
||||
kit: {
|
||||
prerender: { origin: 'https://configure-pages.github.io' },
|
||||
paths: { base: '/docs' },
|
||||
adapter: adapter()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import adapter from '@sveltejs/adapter-auto'
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
kit: {
|
||||
prerender: { origin: 'https://configure-pages.github.io' },
|
||||
paths: { base: '/docs' },
|
||||
adapter: adapter()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const core = require('@actions/core')
|
||||
const { getContext } = require('./context')
|
||||
|
||||
const { findOrCreatePagesSite } = require('./api-client')
|
||||
const { setPagesPath } = require('./set-pages-path')
|
||||
const { setPagesConfig } = require('./set-pages-config')
|
||||
const outputPagesBaseUrl = require('./output-pages-base-url')
|
||||
|
||||
async function main() {
|
||||
@@ -15,7 +15,7 @@ async function main() {
|
||||
const siteUrl = new URL(pageObject.html_url)
|
||||
|
||||
if (staticSiteGenerator) {
|
||||
setPagesPath({ staticSiteGenerator, generatorConfigFile, path: siteUrl.pathname })
|
||||
setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl })
|
||||
}
|
||||
outputPagesBaseUrl(siteUrl)
|
||||
core.exportVariable('GITHUB_PAGES', 'true')
|
||||
|
||||
@@ -3,8 +3,10 @@ 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
|
||||
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path }) {
|
||||
// optional configuration file path, and a Pages siteUrl value to inject
|
||||
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
||||
let { pathname, origin } = siteUrl
|
||||
|
||||
switch (staticSiteGenerator) {
|
||||
case 'nuxt':
|
||||
return {
|
||||
@@ -12,7 +14,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
blankConfigurationFile: `${__dirname}/blank-configurations/nuxt.js`,
|
||||
properties: {
|
||||
// Configure a base path on the router
|
||||
'router.base': path,
|
||||
'router.base': pathname,
|
||||
|
||||
// Set the target to static too
|
||||
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
|
||||
@@ -21,14 +23,14 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
}
|
||||
case 'next':
|
||||
// Next does not want a trailing slash
|
||||
path = removeTrailingSlash(path)
|
||||
pathname = removeTrailingSlash(pathname)
|
||||
|
||||
return {
|
||||
configurationFile: generatorConfigFile || './next.config.js',
|
||||
blankConfigurationFile: `${__dirname}/blank-configurations/next.js`,
|
||||
properties: {
|
||||
// Configure a base path
|
||||
basePath: path,
|
||||
basePath: pathname,
|
||||
|
||||
// Disable server side image optimization too
|
||||
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
||||
@@ -41,19 +43,23 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
blankConfigurationFile: `${__dirname}/blank-configurations/gatsby.js`,
|
||||
properties: {
|
||||
// Configure a path prefix
|
||||
pathPrefix: path
|
||||
pathPrefix: pathname,
|
||||
// Configure a site url
|
||||
'siteMetadata.siteUrl': origin
|
||||
}
|
||||
}
|
||||
case 'sveltekit':
|
||||
// SvelteKit does not want a trailing slash
|
||||
path = removeTrailingSlash(path)
|
||||
pathname = removeTrailingSlash(pathname)
|
||||
|
||||
return {
|
||||
configurationFile: generatorConfigFile || './svelte.config.js',
|
||||
blankConfigurationFile: `${__dirname}/blank-configurations/sveltekit.js`,
|
||||
properties: {
|
||||
// Configure a base path
|
||||
'kit.paths.base': path
|
||||
'kit.paths.base': pathname,
|
||||
// Configure a prerender origin
|
||||
'kit.prerender.origin': origin
|
||||
}
|
||||
}
|
||||
default:
|
||||
@@ -62,10 +68,10 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
|
||||
}
|
||||
|
||||
// Inject Pages configuration in a given static site generator's configuration file
|
||||
function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) {
|
||||
function setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
||||
try {
|
||||
// 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()
|
||||
} catch (error) {
|
||||
// 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 core = require('@actions/core')
|
||||
|
||||
const { getConfigParserSettings } = require('./set-pages-path')
|
||||
const { getConfigParserSettings } = require('./set-pages-config')
|
||||
const { ConfigParser } = require('./config-parser')
|
||||
const { getTempFolder, compareFiles } = require('./test-helpers')
|
||||
|
||||
@@ -32,6 +32,9 @@ describe('configParser', () => {
|
||||
// Get fixture files, excluding expected results
|
||||
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
|
||||
const defaultFileExtension = '.js'
|
||||
configurationFiles
|
||||
@@ -48,7 +51,7 @@ describe('configParser', () => {
|
||||
}
|
||||
|
||||
// Get settings for the static site generator
|
||||
const settings = getConfigParserSettings({ staticSiteGenerator, path: '/docs/' })
|
||||
const settings = getConfigParserSettings({ staticSiteGenerator, siteUrl })
|
||||
// Update the settings
|
||||
settings.configurationFile = fixtureTargetFile
|
||||
// Do the injection
|
||||
@@ -84,7 +87,7 @@ describe('configParser', () => {
|
||||
const settings = getConfigParserSettings({
|
||||
staticSiteGenerator,
|
||||
generatorConfigFile: fixtureTargetFile,
|
||||
path: '/docs/'
|
||||
siteUrl
|
||||
})
|
||||
|
||||
// Do the injection
|
||||
Reference in New Issue
Block a user