Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'gatsby-core-utils' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const icons = pluginOptions.icons || defaultIcons
const legacy =
typeof pluginOptions.legacy !== `undefined` ? pluginOptions.legacy : true
const cacheBusting =
typeof pluginOptions.cache_busting_mode !== `undefined`
? pluginOptions.cache_busting_mode
: `query`
// If icons were generated, also add a favicon link.
if (srcIconExists) {
const favicon = icons && icons.length ? icons[0].src : null
if (cacheBusting !== `none`) {
iconDigest = createContentDigest(fs.readFileSync(pluginOptions.icon))
}
const insertFaviconLinkTag =
typeof pluginOptions.include_favicon !== `undefined`
? pluginOptions.include_favicon
: true
if (favicon && insertFaviconLinkTag) {
headComponents.push(
)
}
// (there will always be one active connection since the dev server
// keeps a connection open for hot module reloading so we can't wait
// for networkidle0)
//
// unfortunately, this increases the minimum load time per route to
// ~500ms, which adds up quickly on large sites; there may be room
// for optimization here
logger.info(`visit`, route)
await page.goto(endpoint(route), { waitUntil: `networkidle2` })
bar.tick()
}
await browser.close()
logger.resetAdapter()
cache.hash = createContentDigest(routes)
cache.timestamp = Date.now()
await save(cache)
logger.print(`
${green(`ok!`)} a mapping between your application's routes and
font requirements has been generated; make sure to
add ${bold(`\`gatsby-plugin-preload-fonts\``)} to your app config
- ${dim(`output`)} ${bold(cacheFile)}
`)
}
${red(`err`)} could not establish a connection with the dev server
attempted connection to ${endpoint}
make sure you've run \`gatsby develop\` and set the
following env variables (if necessary)
- ${bold(`HOST`)} ${dim(`(default: localhost)`)}
- ${bold(`PORT`)} ${dim(`(default: 8000)`)}
- ${bold(`LOG_LEVEL`)} ${dim(`(default: error)`)}
- ${bold(`GRAPHQL_PATH`)} ${dim(`(default: /___graphql)`)}
`)
}
const routesHash = createContentDigest(routes)
if (cache.hash === routesHash) {
const lastRun = formatRelative(new Date(cache.timestamp), new Date())
const ok = await logger.confirm(`
${blue(`note`)} routes have not changed from the last run; if you haven't
added any new routes or font requirements since then, you
should be good to go! would you like to crawl them anyways?
- ${dim(`last run`)} ${bold(lastRun)}
- ${dim(`route hash`)} ${bold(cache.hash)}
`)
if (!ok) process.exit(0)
}
return routes
const writeAndMove = (file, data) => {
const destination = joinPath(program.directory, `.cache`, file)
const tmp = `${destination}.${Date.now()}`
return fs
.writeFile(tmp, data)
.then(() => fs.move(tmp, destination, { overwrite: true }))
}
c =>
` "${c.componentChunkName}": hot(preferDefault(require("${joinPath(
c.component
)}")))`
)
getNode,
createNodeId,
loadNodeContent,
createContentDigest,
}) => {
if (node.internal.type !== 'Mdx') return
const parent = getNode(node.parent)
if (parent.sourceInstanceName !== source) return
const id = createNodeId(`${node.id} >>> MdxRecipe`)
const filepath = createFilePath({
node: parent,
getNode,
basePath: source,
})
const slug = urlResolve(basePath, filepath)
await actions.createNode({
id,
name: node.frontmatter.name || filepath,
slug,
parent: node.id,
children: [],
internal: {
type: 'MdxRecipe',
contentDigest: createContentDigest(node.rawBody),
},
content: node.rawBody,
description: 'Code recipes',
})
actions.createParentChildLink({