Rewrite example js/assets paths to the gh-pages CDN#5840
Conversation
Point the ../../js/ and ../../assets/ references in the gh-pages examples at the jsDelivr-hosted aframevr/aframe@gh-pages copies so the examples load their helper scripts and assets from the CDN. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Looks good, though I'm slightly concerned with the fragility of the approach. For example if we end up with a deeper nested examples at some point, it might reference Maybe we could expand the regex to include the opening |
|
Also, now that the number of replacements is increasing, it might make sense to ensure these are done in one go, instead of calling Edit: never mind, seems to be doing a loop as well. |
| htmlReplace('../../../dist/aframe-master.js', `https://aframe.io/releases/${aframeVersion}/aframe.min.js`); | ||
| htmlReplace(/\.\.\/\.\.\/\.\.\/super-three-package/g, `https://cdn.jsdelivr.net/npm/super-three@${threeVersion}`); | ||
| htmlReplace(/\.\.\/\.\.\/js\//g, 'https://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/js/'); | ||
| htmlReplace(/\.\.\/\.\.\/assets\//g, 'https://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/assets/'); |
There was a problem hiding this comment.
function htmlReplace (before, after) {
return (input) => input.replace(before, after);
}
replaceInFileSync({
files: 'gh-pages/**/*.html',
processor: [
htmlReplace('../../../dist/aframe-master.module.min.js', `https://aframe.io/releases/${aframeVersion}/aframe.module.min.js`),
htmlReplace('../../../dist/aframe-master.js', `https://aframe.io/releases/${aframeVersion}/aframe.min.js`),
htmlReplace(/\.\.\/\.\.\/\.\.\/super-three-package/g, `https://cdn.jsdelivr.net/npm/super-three@${threeVersion}`),
htmlReplace(/\.\.\/\.\.\/js\//g, 'https://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/js/'),
htmlReplace(/\.\.\/\.\.\/assets\//g, 'https://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/assets/')
]
});This way we can avoid opening and writing files multiple times.
There was a problem hiding this comment.
Yes, I even removed the replace-in-file dependency, actually removing 10 packages, and I wrote a simple 9 lines replaceInFileSync function. We have fs.globSync since node 22, no need for a glob dependency.
…replaceInFileSync function, no need for 10 dependencies
…lid URL for future examples with another directory depth
|
I did a copy of the examples directory before and after the refactoring and compared, it's the same. Good to merge. |
|
thanks |
Description
Point the
../../js/and../../assets/references in the gh-pages examples at the jsDelivr-hostedaframevr/aframe@gh-pagescopies, e.g.:../../js/hide-on-play.js→https://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/js/hide-on-play.jsThis makes the released examples load their helper scripts and assets from the CDN rather than relative paths.
🤖 Generated with Claude Code