Skip to content

Commit

Permalink
Revert "fix: move script injection into plugin for nitro compat (#85)"
Browse files Browse the repository at this point in the history
This reverts commit fb31651.
  • Loading branch information
atinux committed May 20, 2021
1 parent 9965476 commit 76bfc7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 14 additions & 4 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ export default async function (moduleOptions) {
...moduleOptions
}, defaults)

// Add all templates
const templatesDir = resolve(__dirname, 'templates')
await addTemplates.call(this, templatesDir, 'color-mode', options)

// Add script to head to detect user or system preference before loading Nuxt (for SSR)
const scriptPath = resolve(__dirname, 'script.min.js')
const scriptT = await fsp.readFile(scriptPath, 'utf-8')
const script = template(scriptT)({ options })

options.script = script
/* istanbul ignore next */
this.options.head.script = this.options.head.script || []
this.options.head.script.push({
hid: options.hid,
innerHTML: script,
pbody: true
})

// Add all templates
const templatesDir = resolve(__dirname, 'templates')
await addTemplates.call(this, templatesDir, 'color-mode', options)
const serializeProp = '__dangerouslyDisableSanitizersByTagID'
this.options.head[serializeProp] = this.options.head[serializeProp] || {}
this.options.head[serializeProp][options.hid] = ['innerHTML']
}
12 changes: 0 additions & 12 deletions lib/templates/plugin.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ import colorSchemeComponent from './color-scheme'

Vue.component('<%= options.componentName %>', colorSchemeComponent)

const serializeProp = '__dangerouslyDisableSanitizersByTagID'
const script = {
hid: '<%= options.hid %>',
innerHTML: `<%= options.script %>`,
pbody: true
}

export default function (ctx, inject) {
ctx.app.head.script.push(script)

ctx.app.head[serializeProp] = ctx.app.head[serializeProp] || {}
ctx.app.head[serializeProp]['<%= options.hid %>'] = ['innerHTML']

const preference = '<%= options.preference %>'

const colorMode = {
Expand Down

0 comments on commit 76bfc7e

Please sign in to comment.