Skip to content

Commit

Permalink
Make Universe browser more robust (#22)
Browse files Browse the repository at this point in the history
* Make the universe browser more robust. (#20)

* Fixed Dependencies.
  • Loading branch information
joerg84 committed May 18, 2018
1 parent b8ddec6 commit 614afd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
10 changes: 5 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"angular": "1.5.8",
"angular-resource": "1.5.8",
"angular-route": "1.5.8",
"angular-bootstrap": "^2.2.0",
"angular-ui-select": "^0.19.6",
"angular-sanitize": "^1.5.8",
"angular-animate": "^1.5.8",
"angular-touch": "^1.5.8",
"angular-bootstrap": "2.2.0",
"angular-ui-select": "0.19.6",
"angular-sanitize": "1.5.8",
"angular-animate": "1.5.8",
"angular-touch": "1.5.8",
"angular-truncate": "*"
},
"resolutions": {
Expand Down
45 changes: 24 additions & 21 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,31 @@ function fillExamples() {
}
// Check if we have a valid example
if (exampleVersions.length > 0) {
// Read README.md contents (for the latest existing version)
var exampleContents = fs.readFileSync(dcosExamplesFolder + "/" + packageName + "/" + exampleVersions[exampleVersions.length-1] + "/README.md", "utf8").toString();
// Get relative links
var relativeLinks = exampleContents.match(relativeLinkRegExp);
// Check if anchor links found
if (relativeLinks && relativeLinks.length > 0) {
// Handle relative links -> Replace with full link including the anchor
relativeLinks.forEach(function (relativeLink) {
var bareLink = relativeLink.replace("(", "").replace(")", "").replace(/-/g, "");
var replaceRelativeLink = "(/#/package/" + packageName + "/docs" + bareLink + ")";
exampleContents = exampleContents.replace(relativeLink, replaceRelativeLink)
});
var filename = dcosExamplesFolder + "/" + packageName + "/" + exampleVersions[exampleVersions.length-1] + "/README.md";
if (fs.existsSync(filename)) {
// Read README.md contents (for the latest existing version)
var exampleContents = fs.readFileSync(filename, "utf8").toString();
// Get relative links
var relativeLinks = exampleContents.match(relativeLinkRegExp);
// Check if anchor links found
if (relativeLinks && relativeLinks.length > 0) {
// Handle relative links -> Replace with full link including the anchor
relativeLinks.forEach(function (relativeLink) {
var bareLink = relativeLink.replace("(", "").replace(")", "").replace(/-/g, "");
var replaceRelativeLink = "(/#/package/" + packageName + "/docs" + bareLink + ")";
exampleContents = exampleContents.replace(relativeLink, replaceRelativeLink)
});
}
// Convert to HTML and replace image sources
var htmlCode = converter.makeHtml(exampleContents).replace(/img\//g, baseUrl + "/" + exampleVersions[exampleVersions.length-1] + "/img/"); // Replace relative URL with absolute URL

// There is an example for this package
exampleCache[packageName] = {
renderedHtml: htmlCode,
enabled: true,
exampleVersion: exampleVersions[exampleVersions.length-1]
};
}
// Convert to HTML and replace image sources
var htmlCode = converter.makeHtml(exampleContents).replace(/img\//g, baseUrl + "/" + exampleVersions[exampleVersions.length-1] + "/img/"); // Replace relative URL with absolute URL

// There is an example for this package
exampleCache[packageName] = {
renderedHtml: htmlCode,
enabled: true,
exampleVersion: exampleVersions[exampleVersions.length-1]
};
}
}
});
Expand Down

0 comments on commit 614afd3

Please sign in to comment.