Skip to content

Commit

Permalink
fix: React CDN
Browse files Browse the repository at this point in the history
- The previous one (cdn.skypack.dev) was throwing a building error.
It was changed to esm.sh.
  • Loading branch information
jeysonj2 committed Jul 26, 2023
1 parent e517598 commit ebd7a6a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/_includes/default.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
data-library-npmdir="{{ meta.npmdir }}"
data-library-package-organization="{{ meta.packageOrganization }}"
data-library-package-name="{{ meta.packageName }}"
data-library-package-full-name="{{ meta.packageFullName }}"
data-library-package-full-name-with-version="{{ meta.packageFullNameWithVersion }}"
data-library-package-url="{{ meta.packageUrl }}"
data-library-react-version="{{ meta.reactVersion }}"
data-library-react-cdn-url="{{ meta.reactCdnUrl }}"
Expand Down
10 changes: 7 additions & 3 deletions docs/_utilities/docs-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DEFAULT_DOCS_CONFIGURATION = {
sponsorUrl: 'https://github.com/sponsors/claviska',
// Configuration variables related to the react playground
reactVersion: '18.2.0',
reactCdnUrl: `https://cdn.skypack.dev`,
reactCdnUrl: 'https://esm.sh',
// Library name to be used in the docs
libraryName: 'Circular'
};
Expand Down Expand Up @@ -44,8 +44,10 @@ const setDocsConfig = newConfig => {
// Updating the variables which are composed by other package data
const packageUrlNoVersion = `${config.packagesCdnUrl}/${config.packageOrganization}/${config.packageName}`;
const packageUrl = `${config.packagesCdnUrl}/${config.packageOrganization}/${config.packageName}@${config.packageVersion}`;
const packageFullName = `${config.packageOrganization}/${config.packageName}`;
const packageFullNameWithVersion = `${packageFullName}@${config.packageVersion}`;
const reactUrl = `${config.reactCdnUrl}/react@${config.reactVersion}`;
const reactPackageUrl = `${config.reactCdnUrl}/${config.packageOrganization}/${config.packageName}@${config.packageVersion}`;
const reactPackageUrl = `${config.reactCdnUrl}/${packageFullNameWithVersion}`;

circularDocsStorage.setItem(
'o-package-data',
Expand All @@ -54,7 +56,9 @@ const setDocsConfig = newConfig => {
packageUrlNoVersion,
packageUrl,
reactUrl,
reactPackageUrl
reactPackageUrl,
packageFullName,
packageFullNameWithVersion
})
);
};
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/scripts/code-previews.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
const reactVersion = document.documentElement.getAttribute('data-library-react-version');
const cdndir = document.documentElement.getAttribute('data-library-cdndir');
const npmdir = document.documentElement.getAttribute('data-library-npmdir');
const packageOrganization = document.documentElement.getAttribute('data-library-package-organization');
const packageName = document.documentElement.getAttribute('data-library-package-name');
const packageFullName = document.documentElement.getAttribute('data-library-package-full-name');
const packageUrl = document.documentElement.getAttribute('data-library-package-url');
const reactCdnUrl = document.documentElement.getAttribute('data-library-react-cdn-url');
const reactUrl = document.documentElement.getAttribute('data-library-react-url');
const reactPackageUrl = document.documentElement.getAttribute('data-library-react-package-url');

function convertModuleLinks(html) {
html = html
.replace(new RegExp(`${packageOrganization}/${packageName}`, 'g'), reactPackageUrl)
.replace(new RegExp(`${packageFullName}`, 'g'), reactPackageUrl)
.replace(/from 'react'/g, `from '${reactUrl}'`)
.replace(/from "react"/g, `from "${reactUrl}"`);

Expand Down
6 changes: 5 additions & 1 deletion docs/eleventy.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ module.exports = function (eleventyConfig) {
{ pattern: 'O-PACKAGE-NAME-O', replacement: `${docsConfig.packageName}` },
{
pattern: 'O-PACKAGE-FULL-NAME-O',
replacement: `${docsConfig.packageOrganization}/${docsConfig.packageName}`
replacement: `${docsConfig.packageFullName}`
},
{
pattern: 'O-PACKAGE-FULL-NAME-WITH-VERSION-O',
replacement: `${docsConfig.packageFullNameWithVersion}`
},
{ pattern: 'O-PACKAGE-URL-O', replacement: `${docsConfig.packageUrl}` },
{ pattern: 'O-DOCS-WEBSITE-O', replacement: `${docsConfig.docsWebsite}` },
Expand Down

0 comments on commit ebd7a6a

Please sign in to comment.