Skip to content

Commit

Permalink
fix(nitro): support vue-meta (compat)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 17, 2021
1 parent ce60dda commit f0cd329
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/runtime/app/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,40 @@ function renderHTML (payload, rendered, ssrContext) {
const state = `<script>window.__NUXT__=${devalue(payload)}</script>`
const _html = rendered.html

const { htmlAttrs = '', bodyAttrs = '', headTags = '', headAttrs = '' } =
(ssrContext.head && ssrContext.head()) || {}
const meta = {
htmlAttrs: '',
bodyAttrs: '',
headAttrs: '',
headTags: '',
bodyTags: ''
}

// @vueuse/head
if (typeof ssrContext.head === 'function') {
Object.assign(meta, ssrContext.head())
}

// vue-meta
if (ssrContext.meta && typeof ssrContext.meta.inject === 'function') {
const _meta = ssrContext.meta.inject({
isSSR: ssrContext.nuxt.serverRendered,
ln: process.env.NODE_ENV === 'development'
})
meta.htmlAttrs += _meta.htmlAttrs.text()
meta.headAttrs += _meta.headAttrs.text()
meta.bodyAttrs += _meta.bodyAttrs.text()
meta.headTags +=
_meta.title.text() + _meta.meta.text() +
_meta.link.text() + _meta.style.text() +
_meta.script.text() + _meta.noscript.text()
// TODO: Body prepend/append tags
}

return htmlTemplate({
HTML_ATTRS: htmlAttrs,
HEAD_ATTRS: headAttrs,
BODY_ATTRS: bodyAttrs,
HEAD: headTags +
HTML_ATTRS: meta.htmlAttrs,
HEAD_ATTRS: meta.headAttrs,
BODY_ATTRS: meta.bodyAttrs,
HEAD: meta.headTags +
rendered.renderResourceHints() + rendered.renderStyles() + (ssrContext.styles || ''),
APP: _html + state + rendered.renderScripts()
})
Expand Down

0 comments on commit f0cd329

Please sign in to comment.