Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/helpers/assets-manifest.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const { execSync } = require('child_process')
const fs = require('fs')
const logger = require('@antora/logger')('assets-manifest-helper')

module.exports = (assetPath) => {
let manifestPath
let manifest
try {
manifestPath = execSync('find ./build/site -name assets-manifest.json').toString().trim()
Copy link
Collaborator Author

@colegoldsmith colegoldsmith Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized we can't read the UI bundle files at this point in the Antora build because the 'build' folder isn't created until after the page composer step (where these handlebars helpers are used). The only way I see to access this assets-manifest file is using the uiCatalog in an Antora extension and somehow make that object available to this helper, thus the global context

manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'))
} catch (err) {
logger.error(err)
const manifest = global.assetsManifest
if (!manifest) {
logger.error(
`
Assets manifest not found in global context.
The .js and .css files from the UI bundle will not be linked properly in the HTML.
Ensure assets-manifest.json from the UI bundle is parsed and added
to global.assetsManifest after uiLoader is complete.
`
)
return assetPath
}
if (manifest) return manifest[assetPath]
return assetPath
return manifest[assetPath]
}