mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-13 18:50:11 -04:00
* refactor(website): use prop and CSS for plugin label spacing * fix: add official tier label to built-in plugin docs * feat(website): add BadgesHeader component * refactor(website): use BadgesHeader in all content * feat(website): add HCP ready demo, tweak badge look * refactor: integrate work from add-plugin-version branch * fix(website): correct bad import * fix: use updated MDX custom component * chore: remove plugin version label work from this branch * chore: remove unused var * fix: use new BadgesHeader interface for dual tags * chore: remove unused var, refine comment * fix: remove unused broken import * fix: shorten property for HCP packer readiness * Apply suggestions from code review Remove a few demo labels before merging Co-authored-by: Wilken Rivera <dev@wilkenrivera.com>
93 lines
3 KiB
JavaScript
93 lines
3 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import {
|
|
getNodeFromPath,
|
|
getPathsFromNavData,
|
|
} from '@hashicorp/react-docs-page/server'
|
|
import renderPageMdx from '@hashicorp/react-docs-page/render-page-mdx'
|
|
import resolveNavData from './utils/resolve-nav-data'
|
|
|
|
async function generateStaticPaths({
|
|
navDataFile,
|
|
localContentDir,
|
|
remotePluginsFile,
|
|
}) {
|
|
const navData = await resolveNavData(navDataFile, localContentDir, {
|
|
remotePluginsFile,
|
|
})
|
|
const paths = await getPathsFromNavData(navData)
|
|
return paths
|
|
}
|
|
|
|
async function generateStaticProps({
|
|
additionalComponents,
|
|
localContentDir,
|
|
mainBranch = 'main',
|
|
navDataFile,
|
|
params,
|
|
product,
|
|
remotePluginsFile,
|
|
}) {
|
|
// Build the currentPath from page parameters
|
|
const currentPath = params.page ? params.page.join('/') : ''
|
|
// Resolve navData, including the possibility that this
|
|
// page is a remote plugin docs, in which case we'll provide
|
|
// the MDX fileString in the resolved navData
|
|
const navData = await resolveNavData(navDataFile, localContentDir, {
|
|
remotePluginsFile,
|
|
currentPath,
|
|
})
|
|
const navNode = getNodeFromPath(currentPath, navData, localContentDir)
|
|
const { filePath, remoteFile, pluginData } = navNode
|
|
// Fetch the MDX file content
|
|
const mdxString = remoteFile
|
|
? remoteFile.fileString
|
|
: fs.readFileSync(path.join(process.cwd(), filePath), 'utf8')
|
|
// Construct the githubFileUrl, used for "Edit this page" link
|
|
// Note: we expect remote files, such as those used to render plugin docs,
|
|
// to have a sourceUrl defined, that points to the file we built from
|
|
const githubFileUrl = remoteFile
|
|
? remoteFile.sourceUrl
|
|
: `https://github.com/hashicorp/${product.slug}/blob/${mainBranch}/website/${filePath}`
|
|
// For plugin pages, prefix the MDX content with a
|
|
// label that reflects the plugin tier
|
|
// (current options are "Official" or "Community")
|
|
// and display whether the plugin is "HCP Packer Ready".
|
|
// Also add a badge to show the latest version
|
|
function mdxContentHook(mdxContent) {
|
|
const badgesMdx = []
|
|
// Add a badge for the plugin tier
|
|
if (pluginData?.tier) {
|
|
badgesMdx.push(`<PluginBadge type="${pluginData.tier}" />`)
|
|
}
|
|
// Add a badge if the plugin is "HCP Packer Ready"
|
|
if (pluginData?.isHcpPackerReady) {
|
|
badgesMdx.push(`<PluginBadge type="hcp_packer_ready" />`)
|
|
}
|
|
// If we have badges to add, inject them into the MDX
|
|
if (badgesMdx.length > 0) {
|
|
const badgeChildrenMdx = badgesMdx.join('')
|
|
const badgesHeaderMdx = `<BadgesHeader>${badgeChildrenMdx}</BadgesHeader>`
|
|
mdxContent = badgesHeaderMdx + '\n\n' + mdxContent
|
|
}
|
|
return mdxContent
|
|
}
|
|
const { mdxSource, frontMatter } = await renderPageMdx(mdxString, {
|
|
additionalComponents,
|
|
productName: product.name,
|
|
mdxContentHook,
|
|
})
|
|
|
|
return {
|
|
currentPath,
|
|
frontMatter,
|
|
mdxSource,
|
|
mdxString,
|
|
githubFileUrl,
|
|
navData,
|
|
navNode,
|
|
}
|
|
}
|
|
|
|
export default { generateStaticPaths, generateStaticProps }
|
|
export { generateStaticPaths, generateStaticProps }
|