-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change: vanilla vite / vue setups will require modifying their configuration
- Loading branch information
Showing
15 changed files
with
132 additions
and
195 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useVueUseHead' |
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,42 @@ | ||
import { computed, watchEffect } from 'vue' | ||
import type { HeadClient } from '@vueuse/head' | ||
import { injectHead } from '@vueuse/head' | ||
|
||
export function useVueUseHead(headClient?: HeadClient) { | ||
let _domSetup = false | ||
|
||
return ({ schemaRef, debug }: any) => { | ||
let head: HeadClient | null = null | ||
try { | ||
// head may not be available in SSR (vitepress) | ||
head = headClient || injectHead() | ||
} | ||
catch (e) { | ||
debug('DOM setup failed, couldn\'t fetch injectHead') | ||
} | ||
if (!head) | ||
return | ||
|
||
// we only need to init the DOM once since we have a reactive head object and a watcher to update the DOM | ||
if (_domSetup) | ||
return | ||
|
||
head.addHeadObjs(computed(() => { | ||
return { | ||
// Can be static or computed | ||
script: [ | ||
{ | ||
type: 'application/ld+json', | ||
key: 'root-schema-org-graph', | ||
children: schemaRef.value, | ||
}, | ||
], | ||
} | ||
})) | ||
watchEffect(() => { | ||
if (head && typeof window !== 'undefined') | ||
head.updateDOM() | ||
}) | ||
_domSetup = true | ||
} | ||
} |
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
Oops, something went wrong.