This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bridge): use
useMeta
in bridge projects (#664)
- Loading branch information
Showing
16 changed files
with
149 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { resolve } from 'pathe' | ||
import { addTemplate, useNuxt, installModule } from '@nuxt/kit' | ||
import metaModule from '../../nuxt3/src/meta/module' | ||
import { distDir } from './dirs' | ||
|
||
const checkDocsMsg = 'Please see https://v3.nuxtjs.org for more information.' | ||
const msgPrefix = '[bridge] [meta]' | ||
|
||
interface SetupMetaOptions { | ||
needsExplicitEnable?: boolean | ||
} | ||
|
||
export const setupMeta = async (opts: SetupMetaOptions) => { | ||
const nuxt = useNuxt() | ||
|
||
if (opts.needsExplicitEnable) { | ||
const metaPath = addTemplate({ | ||
filename: 'meta.mjs', | ||
getContents: () => `export const useMeta = () => console.warn('${msgPrefix} To use \`useMeta\`, please set \`bridge.meta\` to \`true\` in your \`nuxt.config\`. ${checkDocsMsg}')` | ||
}) | ||
nuxt.options.alias['#meta'] = metaPath.dst | ||
return | ||
} | ||
|
||
if (nuxt.options.head && typeof nuxt.options.head === 'function') { | ||
throw new TypeError(`${msgPrefix} The head() function in \`nuxt.config\` has been deprecated and in nuxt3 will need to be moved to \`app.vue\`. ${checkDocsMsg}`) | ||
} | ||
|
||
const runtimeDir = resolve(distDir, 'runtime/meta') | ||
nuxt.options.alias['#meta'] = runtimeDir | ||
|
||
await installModule(nuxt, metaModule) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../nuxt3/src/meta/runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,49 @@ | ||
export default ({ ssrContext }) => { | ||
ssrContext.renderMeta = () => { | ||
const meta = ssrContext.meta.inject({ | ||
isSSR: ssrContext.nuxt.serverRendered, | ||
ln: process.env.NODE_ENV === 'development' | ||
}) | ||
const vueMetaRenderer = (nuxt) => { | ||
const meta = nuxt.ssrContext.meta.inject({ | ||
isSSR: nuxt.ssrContext.nuxt.serverRendered, | ||
ln: process.env.NODE_ENV === 'development' | ||
}) | ||
|
||
return { | ||
htmlAttrs: meta.htmlAttrs.text(), | ||
headAttrs: meta.headAttrs.text(), | ||
headTags: | ||
return { | ||
htmlAttrs: meta.htmlAttrs.text(), | ||
headAttrs: meta.headAttrs.text(), | ||
headTags: | ||
meta.title.text() + meta.base.text() + | ||
meta.meta.text() + meta.link.text() + | ||
meta.style.text() + meta.script.text() + | ||
meta.noscript.text(), | ||
bodyAttrs: meta.bodyAttrs.text(), | ||
bodyScriptsPrepend: | ||
bodyAttrs: meta.bodyAttrs.text(), | ||
bodyScriptsPrepend: | ||
meta.meta.text({ pbody: true }) + meta.link.text({ pbody: true }) + | ||
meta.style.text({ pbody: true }) + meta.script.text({ pbody: true }) + | ||
meta.noscript.text({ pbody: true }), | ||
bodyScripts: | ||
bodyScripts: | ||
meta.meta.text({ body: true }) + meta.link.text({ body: true }) + | ||
meta.style.text({ body: true }) + meta.script.text({ body: true }) + | ||
meta.noscript.text({ body: true }) | ||
} | ||
} | ||
} | ||
|
||
export default defineNuxtPlugin((nuxt) => { | ||
const metaRenderers = [vueMetaRenderer] | ||
|
||
nuxt.callHook('meta:register', metaRenderers) | ||
|
||
nuxt.ssrContext.renderMeta = async () => { | ||
const metadata = { | ||
htmlAttrs: '', | ||
headAttrs: '', | ||
headTags: '', | ||
bodyAttrs: '', | ||
bodyScriptsPrepend: '', | ||
bodyScripts: '' | ||
} | ||
for await (const renderer of metaRenderers) { | ||
const result = await renderer(nuxt) | ||
for (const key in result) { | ||
metadata[key] += result[key] | ||
} | ||
} | ||
return metadata | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Vue from '#vue' | ||
|
||
export * from '@vue/composition-api' | ||
|
||
export const isFunction = fn => fn instanceof Function | ||
|
||
export { Vue as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters