@agency-undone/nuxt-module-ipfs
Version:
A Nuxt module that enables nuxt routing for both the intended path and IPFS gateway URLs, which include a CID (hash)
28 lines (24 loc) • 856 B
JavaScript
/*
*
* 🔌 [Plugin | NuxtModuleIpfs] Methods
*
*/
if (process.server) {
console.log(`🔌 [Module | NuxtModuleIpfs] Methods`)
}
// /////////////////////////////////////////////////////////////////// Functions
// -----------------------------------------------------------------------------
// ------------------------------------------------------------------ relativity
const Relativity = function (path) {
if (process.client) {
if (!path) { return '' }
const ipfsMatch = window.location.pathname.match(/^(\/(?:ipfs|ipns)\/[^/]+)/)
return ipfsMatch ? ipfsMatch[0] + path : path
}
return path
}
// ///////////////////////////////////////////////////////////// Export & Inject
// -----------------------------------------------------------------------------
export default (ctx, inject) => {
inject('relativity', Relativity)
}