Skip to content

Commit

Permalink
Conditionally add custom cc constructor only if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
dylankelly committed Jun 20, 2022
1 parent f0e84a2 commit da093f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/reference/tide/tide.content-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default class CustomContentCollection extends ContentCollection {
// eslint-disable-next-line no-useless-constructor
constructor (configuration, searchEndpoint, environment) {
super(configuration, searchEndpoint, environment)
console.log('custom constructor')
}
// override methods here to change contentcollection behaviour
}
3 changes: 1 addition & 2 deletions packages/ripple-nuxt-tide/lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ const nuxtTide = function (moduleOptions) {

// Content Collection - default to enabled
if (options.modules?.landingPage?.contentCollection !== false) {
const customCCPath = path.resolve('tide/tide.content-collection.js')
this.addPlugin({
src: path.resolve(__dirname, 'templates/content-collection.js'),
fileName: 'tide-content-collection.js',
options: {
useCustomPath: fs.existsSync(customCCPath)
useCustomPath: fs.existsSync('tide/tide.content-collection.js')
}
})
}
Expand Down
14 changes: 7 additions & 7 deletions packages/ripple-nuxt-tide/lib/templates/content-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export default async ({ app, req, store , route }, inject) => {
// https://www.npmjs.com/package/serialize-javascript
const options = <%= serialize(options) %>

let contentCollectionClass = ContentCollection

if (options.useCustomPath) {
contentCollectionClass = await import(/* webpackMode: "lazy" */ '../tide/tide.content-collection.js').then(m => m.default)
}

inject('tideContentCollection', contentCollectionClass)
<% if (options.useCustomPath) { %>
const customConstructor = await import(/* webpackMode: "lazy" */ '../tide/tide.content-collection.js').then(m => m.default)
inject('tideContentCollection', customConstructor)
<% } %>
<% if (!options.useCustomPath) { %>
inject('tideContentCollection', ContentCollection)
<% } %>
}

0 comments on commit da093f2

Please sign in to comment.