Copilot commented on code in PR #1729:
URL: https://github.com/apache/camel-website/pull/1729#discussion_r3790845632
##########
antora-ui-camel/package.json:
##########
@@ -9,41 +9,42 @@
"url": "https://github.com/apache/camel-website.git"
},
"engines": {
- "node": ">= 8.0.0"
+ "node": ">= 18.0.0"
Review Comment:
The declared Node range is incompatible with the new `through2@5` usage.
This package is ESM-only, while the gulp tasks load it with
`require('through2')`; CommonJS `require(esm)` is only supported from Node
22.12, so builds on Node 18 or 20—both allowed here—fail before gulp starts.
Raise the engine floor to 22.12, convert these tasks to ESM, or retain through2
v4.
##########
extensions/detect-unused-media.js:
##########
@@ -0,0 +1,69 @@
+'use strict'
+
+const fs = require('fs')
+const ospath = require('path')
+
+/**
+ * This Antora extension reports image assets that no page or partial
references,
+ * so stray media can be found and deleted.
+ *
+ * It deliberately logs at info and never at warn. The playbook sets
+ * runtime.log.failure_level to warn, so a warning here would fail the whole
site
+ * build over a housekeeping issue. Set failOnUnused to true to opt into that.
+ *
+ * Options:
+ * excludeExtensions extensions to skip, defaults to ['.cast']
+ * reportPath file to write the list to, defaults to
build/unused-media.txt
+ * set to false to skip the report
+ * failOnUnused log at warn instead of info, defaults to false
+ */
+module.exports.register = function ({ config }) {
+ const logger = this.getLogger('detect-unused-media')
+ const {
+ excludeExtensions = ['.cast'],
+ reportPath = ospath.join('build', 'unused-media.txt'),
+ failOnUnused = false,
+ } = config || {}
+ const excluded = new Set(excludeExtensions)
+
+ this.on('contentClassified', ({ contentCatalog }) => {
+ const referenced = collectReferences(contentCatalog)
+ const unused = contentCatalog
+ .getFiles()
+ .filter(({ src }) => src.family === 'image' &&
!excluded.has(src.extname))
+ .filter(({ src }) => !(referenced.has(src.relative) ||
referenced.has(`${src.module}:${src.relative}`)))
+
+ logger.info(
+ 'Checked %s image assets against %s references, %s unused',
+ contentCatalog.getFiles().filter(({ src }) => src.family ===
'image').length,
+ referenced.size,
+ unused.length
+ )
+ if (!unused.length) return
+
+ const lines = unused.map(({ src }) => `${src.component} ${src.version}
${src.path}`).sort()
+ lines.forEach((line) => logger[failOnUnused ? 'warn' : 'info'](line))
+ if (reportPath === false) return
+
+ fs.mkdirSync(ospath.dirname(reportPath), { recursive: true })
+ fs.writeFileSync(reportPath, lines.join('\n') + '\n')
+ logger.info('Wrote the unused media report to %s', reportPath)
+ })
+}
+
+// NOTE the same shapes the crawler-independent extension used: image:target[]
and image::target[]
+// for images, video::target[] for video. Anything the reference cannot be
resolved from, such as a
+// target built from an attribute, is simply not matched, so this
under-reports rather than
+// reporting a used file as unused.
Review Comment:
Unresolved attribute targets produce false positives, not under-reporting.
For example, `image::{image-dir}/logo.svg[]` is stored literally, never equals
the resolved asset's `src.relative`, and therefore causes a used image to be
listed as unused. Resolve attributes/resource IDs in each source file, or
conservatively exclude unresolved targets from deletion candidates.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]