Skip to content

Commit

Permalink
refactor: rename viteAssetMap -> staticAssetMap
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Feb 4, 2025
1 parent 26374c8 commit 626aa73
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
26 changes: 13 additions & 13 deletions baker/GrapherBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ const renderDatapageIfApplicable = async (
knex: db.KnexReadonlyTransaction,
{
imageMetadataDictionary,
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
}: {
imageMetadataDictionary?: Record<string, DbEnrichedImage>
viteAssetMap?: AssetMapEntry
staticAssetMap?: AssetMapEntry
runtimeAssetMap?: AssetMapEntry
} = {}
) => {
Expand All @@ -90,7 +90,7 @@ const renderDatapageIfApplicable = async (
useIndicatorGrapherConfigs: false,
pageGrapher: grapher,
imageMetadataDictionary,
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
},
knex
Expand All @@ -107,17 +107,17 @@ export const renderDataPageOrGrapherPage = async (
knex: db.KnexReadonlyTransaction,
{
imageMetadataDictionary,
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
}: {
imageMetadataDictionary?: Record<string, DbEnrichedImage>
viteAssetMap?: AssetMapEntry
staticAssetMap?: AssetMapEntry
runtimeAssetMap?: AssetMapEntry
} = {}
): Promise<string> => {
const datapage = await renderDatapageIfApplicable(grapher, false, knex, {
imageMetadataDictionary,
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
})
if (datapage) return datapage
Expand All @@ -132,7 +132,7 @@ export async function renderDataPageV2(
useIndicatorGrapherConfigs,
pageGrapher,
imageMetadataDictionary = {},
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
}: {
variableId: number
Expand All @@ -141,7 +141,7 @@ export async function renderDataPageV2(
useIndicatorGrapherConfigs: boolean
pageGrapher?: GrapherInterface
imageMetadataDictionary?: Record<string, ImageMetadata>
viteAssetMap?: AssetMapEntry
staticAssetMap?: AssetMapEntry
runtimeAssetMap?: AssetMapEntry
},
knex: db.KnexReadonlyTransaction
Expand Down Expand Up @@ -239,7 +239,7 @@ export async function renderDataPageV2(
imageMetadata={imageMetadata}
faqEntries={faqEntries}
tagToSlugMap={tagToSlugMap}
viteAssetMap={viteAssetMap}
staticAssetMap={staticAssetMap}
runtimeAssetMap={runtimeAssetMap}
/>
)
Expand Down Expand Up @@ -292,11 +292,11 @@ export const bakeSingleGrapherPageForArchival = async (
knex: db.KnexReadonlyTransaction,
{
imageMetadataDictionary,
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
}: {
imageMetadataDictionary?: Record<string, DbEnrichedImage>
viteAssetMap?: AssetMapEntry
staticAssetMap?: AssetMapEntry
runtimeAssetMap?: AssetMapEntry
} = {}
) => {
Expand All @@ -305,7 +305,7 @@ export const bakeSingleGrapherPageForArchival = async (
outPathHtml,
await renderDataPageOrGrapherPage(grapher, knex, {
imageMetadataDictionary,
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
})
)
Expand All @@ -315,7 +315,7 @@ export const bakeSingleGrapherPageForArchival = async (
// hashes of the config and data files.
await fs.writeFile(
outPathManifest,
JSON.stringify({ viteAssetMap, runtimeAssetMap }, undefined, 2)
JSON.stringify({ staticAssetMap, runtimeAssetMap }, undefined, 2)
)
console.log(outPathHtml, outPathManifest)
}
Expand Down
12 changes: 6 additions & 6 deletions baker/buildLocalArchivalBake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ const bakeAssets = async () => {

await fs.mkdirp(targetDir)

const viteAssetMap: AssetMapEntry = {}
const staticAssetMap: AssetMapEntry = {}

for (const dirent of await fs.readdir(srcDir, { withFileTypes: true })) {
if (!dirent.isFile()) continue
const srcFile = path.join(srcDir, dirent.name)
const filename = await hashAndCopyFile(srcFile, targetDir)
viteAssetMap[dirent.name] = `/${filename}`
staticAssetMap[dirent.name] = `/${filename}`
}
return { viteAssetMap }
return { staticAssetMap }
}

const bakeDomainToFolder = async (
Expand All @@ -116,8 +116,8 @@ const bakeDomainToFolder = async (
await fs.mkdirp(dir)
await fs.mkdirp(path.join(dir, "grapher"))

const { viteAssetMap } = await bakeAssets()
const baker = new SiteBaker(dir, baseUrl, bakeSteps, viteAssetMap)
const { staticAssetMap } = await bakeAssets()
const baker = new SiteBaker(dir, baseUrl, bakeSteps, staticAssetMap)

Check warning on line 120 in baker/buildLocalArchivalBake.ts

View workflow job for this annotation

GitHub Actions / eslint

'baker' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 120 in baker/buildLocalArchivalBake.ts

View workflow job for this annotation

GitHub Actions / eslint

'baker' is assigned a value but never used. Allowed unused vars must match /^_/u

console.log(`Baking site locally with baseUrl '${baseUrl}' to dir '${dir}'`)

Expand All @@ -143,7 +143,7 @@ const bakeDomainToFolder = async (

await bakeSingleGrapherPageForArchival(dir, chart.config, trx, {
imageMetadataDictionary,
viteAssetMap,
staticAssetMap,
runtimeAssetMap: runtimeFiles,
})
}, db.TransactionCloseMode.Close)
Expand Down
8 changes: 4 additions & 4 deletions site/DataPageV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const DataPageV2 = (props: {
faqEntries?: FaqEntryData
imageMetadata: Record<string, ImageMetadata>
tagToSlugMap: Record<string | number, string>
viteAssetMap?: AssetMapEntry
staticAssetMap?: AssetMapEntry
runtimeAssetMap?: AssetMapEntry
dataApiUrl?: string
}) => {
Expand All @@ -57,7 +57,7 @@ export const DataPageV2 = (props: {
faqEntries,
tagToSlugMap,
imageMetadata,
viteAssetMap,
staticAssetMap,
runtimeAssetMap,
} = props
const pageTitle = grapher?.title ?? datapageData.title.title
Expand Down Expand Up @@ -113,7 +113,7 @@ export const DataPageV2 = (props: {
pageDesc={pageDesc}
imageUrl={imageUrl}
baseUrl={baseUrl}
viteAssetMap={viteAssetMap}
staticAssetMap={staticAssetMap}
>
<meta property="og:image:width" content={imageWidth} />
<meta property="og:image:height" content={imageHeight} />
Expand Down Expand Up @@ -184,7 +184,7 @@ export const DataPageV2 = (props: {
baseUrl={baseUrl}
context={SiteFooterContext.dataPageV2}
isPreviewing={isPreviewing}
viteAssetMap={viteAssetMap}
staticAssetMap={staticAssetMap}
runtimeAssetMap={runtimeAssetMap}
/>
<script
Expand Down
4 changes: 2 additions & 2 deletions site/Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const Head = (props: {
title: string
href: string
}
viteAssetMap?: AssetMapEntry
staticAssetMap?: AssetMapEntry
}) => {
const { canonicalUrl, hideCanonicalUrl, baseUrl } = props
const pageTitle = props.pageTitle || `Our World in Data`
Expand All @@ -63,7 +63,7 @@ export const Head = (props: {
}

const stylesheets = viteAssetsForSite({
viteAssetMap: props.viteAssetMap,
staticAssetMap: props.staticAssetMap,
}).forHeader

return (
Expand Down
7 changes: 5 additions & 2 deletions site/SiteFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface SiteFooterProps {
context?: SiteFooterContext
debug?: boolean
isPreviewing?: boolean
viteAssetMap?: AssetMapEntry
staticAssetMap?: AssetMapEntry
runtimeAssetMap?: AssetMapEntry
}

Expand Down Expand Up @@ -278,7 +278,10 @@ export const SiteFooter = (props: SiteFooterProps) => (
</div>
</div>
<div className="site-tools" />
{viteAssetsForSite({ viteAssetMap: props.viteAssetMap }).forFooter}
{
viteAssetsForSite({ staticAssetMap: props.staticAssetMap })
.forFooter
}
<ScriptLoadErrorDetector />
<script
type="module"
Expand Down
6 changes: 3 additions & 3 deletions site/viteUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ const viteAssets = (

export const viteAssetsForAdmin = () => viteAssets(ViteEntryPoint.Admin)
export const viteAssetsForSite = ({
viteAssetMap,
}: { viteAssetMap?: AssetMapEntry } = {}) =>
viteAssets(ViteEntryPoint.Site, { prodAssetMap: viteAssetMap })
staticAssetMap,
}: { staticAssetMap?: AssetMapEntry } = {}) =>
viteAssets(ViteEntryPoint.Site, { prodAssetMap: staticAssetMap })

export const generateEmbedSnippet = () => {
// Make sure we're using an absolute URL here, since we don't know in what context the embed snippet is used.
Expand Down

0 comments on commit 626aa73

Please sign in to comment.