Skip to content

Rewrite example js/assets paths to the gh-pages CDN#5840

Merged
dmarcos merged 4 commits into
aframevr:masterfrom
vincentfretin:ghpages-cdn-js-assets
Jun 28, 2026
Merged

Rewrite example js/assets paths to the gh-pages CDN#5840
dmarcos merged 4 commits into
aframevr:masterfrom
vincentfretin:ghpages-cdn-js-assets

Conversation

@vincentfretin

Copy link
Copy Markdown
Contributor

Description

Point the ../../js/ and ../../assets/ references in the gh-pages examples at the jsDelivr-hosted aframevr/aframe@gh-pages copies, e.g.:

../../js/hide-on-play.jshttps://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/js/hide-on-play.js

This makes the released examples load their helper scripts and assets from the CDN rather than relative paths.

🤖 Generated with Claude Code

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>
@mrxz

mrxz commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

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 ../../../js/, so one more indirection.

Maybe we could expand the regex to include the opening "? It won't solve the above, but should avoid generating an invalid URL at least.

@mrxz

mrxz commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Also, now that the number of replacements is increasing, it might make sense to ensure these are done in one go, instead of calling replaceInFileSync multiple times. Not really familiar with the replace-in-file module, but based on the documentation this seems possible: https://github.com/adamreisnz/replace-in-file#multiple-replacements-with-different-options

Edit: never mind, seems to be doing a loop as well.

Comment thread scripts/preghpages.js Outdated
Comment on lines +32 to +44
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/');

@mrxz mrxz Jun 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vincentfretin

Copy link
Copy Markdown
Contributor Author

I did a copy of the examples directory before and after the refactoring and compared, it's the same. Good to merge.

@dmarcos dmarcos merged commit 064590b into aframevr:master Jun 28, 2026
1 check passed
@dmarcos

dmarcos commented Jun 28, 2026

Copy link
Copy Markdown
Member

thanks

@vincentfretin vincentfretin deleted the ghpages-cdn-js-assets branch June 28, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants