Skip to content

Commit d7911a5

Browse files
committed
Feat: $relativity method now detects client-side IPFS prefix in URL // Feat: all JS assets are now forced to load -- no more async // Fix: updated deprecated hook // Feat: added support for parsing CSS url paths
1 parent 379df10 commit d7911a5

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,23 @@ const addHooks = (instance) => {
5656
staticAssetsOpts = generateOptions.staticAssets
5757
})
5858

59+
/*
60+
Force the loading of all Javascript files
61+
*/
62+
63+
instance.nuxt.hook('render:resourcesLoaded', (resources) => {
64+
resources.clientManifest.initial = resources.clientManifest.initial.concat(resources.clientManifest.async)
65+
initialScripts = resources.clientManifest.initial
66+
asyncScripts = resources.clientManifest.async
67+
})
68+
5969
/*
6070
This block gives us access to the generated javascript before it is
6171
serialized
6272
*/
6373

64-
instance.nuxt.hook('render:routeContext', (ctx) => {
65-
parsed = parseRoute(ctx.routePath)
74+
instance.nuxt.hook('vue-renderer:ssr:context', (ctx) => {
75+
parsed = parseRoute(ctx.nuxt.routePath)
6676
// Apply url replacements to generated javascript before it is serialized
6777
ctx.staticAssetsBase = `${parsed.replaceSrc}${staticAssetsOpts.dir}/${staticAssetsOpts.version}`
6878
})
@@ -74,7 +84,10 @@ const addHooks = (instance) => {
7484
instance.nuxt.hook('generate:page', (payload) => {
7585
parsed = parseRoute(payload.route)
7686
// Apply url replacements to generated HTML
77-
payload.html = payload.html.replace(/\/_nuxt\//gi, parsed.replaceSrc).replace(/\/relativity\//gi, parsed.replaceStatic)
87+
payload.html = payload.html
88+
.replace(/"\/_nuxt\//gi, `"${parsed.replaceSrc}`)
89+
.replace(/\(\/_nuxt\//gi, `(${parsed.replaceSrc}`)
90+
.replace(/\/relativity\//gi, parsed.replaceStatic)
7891
})
7992
}
8093

plugin.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ console.log(`🔌 [Module | NuxtModuleIpfs] Methods`)
1010
// -----------------------------------------------------------------------------
1111
// ------------------------------------------------------------------ relativity
1212
const Relativity = (path) => {
13-
const append = path.charAt(0) === '/' ? path.slice(1) : path
1413
if (process.env.NODE_ENV !== 'development') {
15-
if (typeof window !== 'undefined') { return path }
16-
return `/relativity/${append}`
14+
const append = path.charAt(0) === '/' ? path.slice(1) : path;
15+
if (typeof window !== 'undefined') {
16+
const ipfsPathRegExp = /^(\/(?:ipfs|ipns)\/[^/]+)/;
17+
const ipfsPathPrefix = (window.location.pathname.match(ipfsPathRegExp) || [])[1] || '';
18+
if (ipfsPathPrefix) {
19+
return `${ipfsPathPrefix}${path}/`;
20+
} else {
21+
return path;
22+
}
23+
}
24+
return `/relativity/${append}`;
1725
}
18-
return path
26+
return path;
1927
}
2028

2129
// ///////////////////////////////////////////////////////////// Export & Inject

0 commit comments

Comments
 (0)