Skip to content

Commit c424108

Browse files
committed
Improve information presentation
1 parent 6e85268 commit c424108

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

package-list.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
libraries:
2+
packages:
33
- arduino-iot-cloud-py:
44
name: Arduino IoT Cloud Python client
55
url: https://github.com/arduino/arduino-iot-cloud-py

registry-renderer/index.js

+48-27
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,75 @@ const REPO_DESCRIPTION_PATH = "./description.md";
66
const TARGET_PATH = "./README.md";
77

88
/**
9-
* Reads the library list from the YAML file and returns it as a JavaScript object.
9+
* Reads the package list from the YAML file and returns it as a JavaScript object.
1010
* @param {String} path
11-
* @returns an Object representing the library list
11+
* @returns an Object representing the package list
1212
*/
13-
function getLibraryListFromYaml(path) {
13+
function getPackageListFromYaml(path) {
1414
try {
15-
return load(readFileSync(path, 'utf8')).libraries;
15+
let libraries = load(readFileSync(path, 'utf8')).packages;
16+
17+
// Sort libraries by name alphabetically
18+
libraries.sort((a, b) => {
19+
if (a.name < b.name) { return -1; }
20+
if (a.name > b.name) { return 1; }
21+
return 0;
22+
});
23+
24+
return libraries;
1625
} catch (e) {
1726
console.log(e);
1827
}
1928
}
2029

2130
/**
2231
* Turns the properties of the library list into a Markdown string.
23-
* @param {Object} libraryList
32+
* @param {Object} packageList
2433
* @returns A string containing the library list in Markdown format
2534
*/
26-
function getMarkdownFromLibraryList(libraryList) {
27-
const libraryData = libraryList.map(library => {
28-
let entry = `### ${library.name}\n\n${library.description} \n\n`;
29-
30-
if(library.url) {
31-
entry += `- 🌐 **URL:** ${library.url} \n`;
32-
}
33-
if(library.author) {
34-
entry += `- 👤 **Author:** ${library.author} \n`;
35+
function getMarkdownFromPackageList(packageList) {
36+
const libraryData = packageList.map(aPackage => {
37+
let entry = `### [${aPackage.name}](${aPackage.url})\n\n`;
38+
39+
if (aPackage.description) {
40+
entry += `${aPackage.description} \n\n`;
41+
}
42+
43+
entry += "<details><summary>Details</summary>\n";
44+
entry += "<ul>\n";
45+
46+
if (aPackage.url) {
47+
entry += `<li>🌐 <strong>URL:</strong> ${aPackage.url}</li>\n`;
3548
}
36-
if(library.license) {
37-
entry += `- 📜 **License:** ${library.license} \n`;
49+
if (aPackage.author) {
50+
entry += `<li>👤 <strong>Author:</strong> ${aPackage.author}</li>\n`;
3851
}
39-
if(library.tags) {
40-
entry += `- 🏷️ **Tags:** ${library.tags.join(', ')} \n`;
52+
if (aPackage.license) {
53+
entry += `<li>📜 <strong>License:</strong> ${aPackage.license}</li>\n`;
54+
}
55+
if (aPackage.tags) {
56+
entry += `<li>🏷️ <strong>Tags:</strong> ${aPackage.tags.join(', ')}</li>\n`;
4157
}
4258

43-
if(library.verification){
44-
entry += "- ✅ **Verification:**\n";
45-
let verification = library.verification.map(verification => {
59+
if (aPackage.verification) {
60+
entry += "<li>✅ <strong>Verification:</strong>\n<ul>\n";
61+
let verification = aPackage.verification.map(verification => {
4662
const libraryVersion = verification.library_version ? ` v${verification.library_version}` : "";
47-
return ` - Verified${libraryVersion} with \`${verification.fqbn}\` on MicroPython v${verification.micropython_version}`;
63+
return `<li>Verified${libraryVersion} with <code>${verification.fqbn}</code> on MicroPython v${verification.micropython_version}</li>`;
4864
}).join("\n");
49-
entry += `${verification}\n`;
65+
entry += `${verification}\n</ul></li>\n`;
5066
}
67+
68+
entry += "</ul>\n";
69+
entry += "</details>\n\n";
70+
5171
return entry;
52-
72+
5373
}).join("<hr />\n\n");
5474
return `## 📦 Packages\n${libraryData}`;
5575
}
5676

77+
5778
/**
5879
* Merges the repo description and the library list into a
5980
* single Markdown string and writes it to the target file.
@@ -67,8 +88,8 @@ function writeMarkdownFile(descriptionPath, targetPath, markdownLibraryList) {
6788
writeFileSync(targetPath, content);
6889
}
6990

70-
console.log("📚 Rendering library list...");
71-
const libraryList = getLibraryListFromYaml(REGISTRY_FILE_PATH);
72-
const markdownLibraryList = getMarkdownFromLibraryList(libraryList);
91+
console.log("📚 Rendering package list...");
92+
const packageList = getPackageListFromYaml(REGISTRY_FILE_PATH);
93+
const markdownLibraryList = getMarkdownFromPackageList(packageList);
7394
writeMarkdownFile(REPO_DESCRIPTION_PATH, TARGET_PATH, markdownLibraryList);
7495
console.log("✅ Done");

0 commit comments

Comments
 (0)