Skip to content

Commit bf49b04

Browse files
committed
Add a regex replacement to use published version of the library in examples
1 parent 9e7320a commit bf49b04

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

server/scripts/examples-ml5.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ async function fetchFileContent(item) {
7878
options.url !== ''
7979
) {
8080
file.content = await rp(options);
81+
8182
// NOTE: remove the URL property if there's content
8283
// Otherwise the p5 editor will try to pull from that url
8384
if (file.content !== null) delete file.url;
85+
86+
// Replace localhost references with references to the currently published version.
87+
file.content = file.content.replace(
88+
/http:\/\/localhost(:[0-9]+)\/ml5.js/g,
89+
'https://unpkg.com/ml5@latest/dist/ml5.min.js'
90+
);
8491
}
8592

8693
return file;
@@ -124,7 +131,7 @@ async function getCategoryExamples(sketchRootList) {
124131
// let options = Object.assign({url: `${requestOptions.url}/${categories.path}${branchRef}`}, requestOptions)
125132
const options = Object.assign({}, githubRequestOptions);
126133
options.url = `${options.url}${categories.path}${branchRef}`;
127-
// console.log(options)
134+
128135
const sketchDirs = await rp(options);
129136

130137
try {

0 commit comments

Comments
 (0)