This repository was archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 984
feat(bridge): use useMeta in bridge projects
#664
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
958ccad
feat(bridge): use `useMeta` in bridge projects
danielroe 047d356
refactor: allow enabling both nuxt2 `vue-meta` and nuxt3 `useMeta` coβ¦
danielroe 935769a
fix: remove unneeded check
danielroe c1881b6
refactor: extract vue2/3 compat module to `app.ts`
danielroe 28a11c9
refactor: polyfill `vm.type` in vue2
danielroe 4ff2b0c
fix: only enable `useMeta` usage with composition-api support
danielroe 4cd0676
fix: remove unneeded key
danielroe 106e565
fix: revert change to mixin key
danielroe ec3ab1a
refactor: change meta module options syntax
danielroe 9156bf4
Update packages/bridge/src/meta.ts
danielroe d44ca57
fix: type error
danielroe a6bba4c
fix: revert mixin change (pending followup pr)
danielroe 94a1188
Merge branch 'main' into feat/usemeta-bridge
pi0 f1ba4ad
fix: add meta type
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.