Skip to content

Commit 2b1bbbf

Browse files
committed
hardware-catalog: find images based on Zephyr's patterning
Use the same glob pattern approach from the Zephyr Doc generator to locate images for the board catalog: https://github.com/zephyrproject-rtos/zephyr/blob/999b19d6ceaee29902434bda9c160486a3eb75bc/doc/_scripts/gen_boards_catalog.py#L80-L100 This results in a small number of boards having an image selected that is not the ideal image to use. This behavior matches what Zephyr is showing in Docs, and a very large number of boards that didn't have a photo in our board catalog now do. Signed-off-by: Mike Szczys <mike@golioth.io>
1 parent 0686d4f commit 2b1bbbf

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

scripts/device-catalog/index.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,26 @@ function findBoardImage(boardPath, boardId) {
5151
}
5252

5353
// Find image in Zephyr tree
54-
if (!(fs.existsSync(path.join(fullPath, 'doc', docFile)))) {
55-
if (fs.existsSync(path.join(fullPath, 'doc', `${boardId}.rst`))) {
56-
docFile = `${boardId}.rst`;
57-
} else {
58-
return { sourceImg, suffix };
59-
}
60-
}
54+
//
55+
// Uses the same pattern globbing as the Zephyr Docs:
56+
// https://github.com/zephyrproject-rtos/zephyr/blob/999b19d6ceaee29902434bda9c160486a3eb75bc/doc/_scripts/gen_boards_catalog.py#L80-L100
6157

62-
boardDoc = fs.readFileSync(path.join(fullPath, 'doc', docFile), 'utf8');
58+
let docImgPath = path.join(fullPath, 'doc');
6359

64-
for (const line of boardDoc.split('\n')) {
65-
if (line.startsWith('.. figure:: ')) {
66-
sourceImg = path.join(fullPath, 'doc', line.split('.. figure:: ')[1]);
67-
suffix = path.extname(sourceImg);
68-
break;
69-
} else if (line.startsWith('.. image:: ')) {
70-
sourceImg = path.join(fullPath, 'doc', line.split('.. image:: ')[1]);
60+
const img_exts = ["jpg", "jpeg", "webp", "png"];
61+
62+
let patterns = [];
63+
patterns.push(`**/${boardId}.{${img_exts.join()}}`)
64+
patterns.push(`**/*${boardId}*.{${img_exts.join()}}`)
65+
patterns.push(`**/*.{${img_exts.join()}}`)
66+
67+
for (p of patterns) {
68+
img_files = fs.globSync(path.join(fullPath, p));
69+
if (img_files.length > 0)
70+
{
71+
sourceImg = img_files[0];
7172
suffix = path.extname(sourceImg);
72-
break;
73+
return { sourceImg, suffix };
7374
}
7475
}
7576

@@ -319,8 +320,8 @@ fs.writeFileSync(`${docsRoot}/_category_.yml`,
319320

320321
console.log(`Built ${count.built} out of ${count.boards} available boards.`);
321322

322-
console.log('Built: ');
323+
console.log(`\nBuilt [${boards.length}]: `);
323324
console.log(boards.map((b) => `${b.boardId}:${b.boardPath}`).join(' '));
324325

325-
console.log('\nNo image: ');
326+
console.log(`\nNo image [${unbuilt.length}]: `);
326327
console.log(unbuilt.join(' '));

0 commit comments

Comments
 (0)