Skip to content

Commit 064a16f

Browse files
authored
feat(create-gatsby): Add name to site metadata (#28324)
1 parent 231cf9f commit 064a16f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

packages/create-gatsby/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { center, rule, wrap } from "./components/utils"
1313
import { stripIndent } from "common-tags"
1414
import { trackCli } from "./tracking"
1515
import crypto from "crypto"
16+
import { setSiteMetadata } from "./site-metadata"
1617

1718
const sha256 = (str: string): string =>
1819
crypto.createHash(`sha256`).update(str).digest(`hex`)
@@ -301,10 +302,13 @@ ${c.bold(`Thanks! Here's what we'll now do:`)}
301302
c.green(c.symbols.check) + ` Created site in ` + c.green(data.project)
302303
)
303304

305+
const fullPath = path.resolve(data.project)
306+
304307
if (plugins.length) {
305308
console.log(c.bold(`${w(`🔌 `)}Installing plugins...`))
306-
await installPlugins(plugins, pluginConfig, path.resolve(data.project), [])
309+
await installPlugins(plugins, pluginConfig, fullPath, [])
307310
}
311+
await setSiteMetadata(fullPath, `title`, data.project)
308312

309313
const pm = await getPackageManager()
310314

@@ -315,7 +319,7 @@ ${c.bold(`Thanks! Here's what we'll now do:`)}
315319
${w(`🎉 `)}Your new Gatsby site ${c.bold(
316320
data.project
317321
)} has been successfully bootstrapped
318-
at ${c.bold(path.resolve(data.project))}.
322+
at ${c.bold(fullPath)}.
319323
`
320324
)
321325
console.log(`Start by going to the directory with\n
@@ -330,7 +334,7 @@ ${c.bold(`Thanks! Here's what we'll now do:`)}
330334
${c.blueBright(`https://www.gatsbyjs.com/docs/gatsby-cli/`)}
331335
`)
332336

333-
const siteHash = md5(path.resolve(data.project))
337+
const siteHash = md5(fullPath)
334338
trackCli(`CREATE_GATSBY_SUCCESS`, { siteHash })
335339
}
336340

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export async function setSiteMetadata(
2+
root: string,
3+
name: string,
4+
value: string
5+
): Promise<void> {
6+
try {
7+
const recipesPath = require.resolve(`gatsby-recipes`, {
8+
paths: [root],
9+
})
10+
const { GatsbySiteMetadata } = require(recipesPath)
11+
await GatsbySiteMetadata?.create({ root }, { name, value })
12+
} catch (e) {
13+
// Silently fail, as it's fine if we don't add it to the config
14+
}
15+
}

0 commit comments

Comments
 (0)