@vueuse/head
Advanced tools
Comparing version 1.0.0-rc.6 to 1.0.0-rc.7
@@ -98,3 +98,3 @@ import * as vue from 'vue'; | ||
} | ||
declare type TagKeys = keyof Omit<HeadObjectPlain, 'titleTemplate'>; | ||
declare type TagKeys = keyof HeadObjectPlain; | ||
interface HeadTag { | ||
@@ -101,0 +101,0 @@ tag: TagKeys; |
@@ -179,3 +179,3 @@ "use strict"; | ||
const { props, tag: tagName, options } = tag; | ||
if (tagName === "base" || tagName === "title") | ||
if (tagName === "base" || tagName === "title" || tagName === "titleTemplate") | ||
return tagName; | ||
@@ -226,4 +226,3 @@ if (tagName === "link" && props.rel === "canonical") | ||
runtime: { | ||
entryId: e.id, | ||
position: 0 | ||
entryId: e.id | ||
}, | ||
@@ -258,7 +257,14 @@ options: { | ||
var headInputToTags = (e) => { | ||
return Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && v !== null && k !== "titleTemplate").map(([key, value]) => { | ||
return Object.entries(e.input).filter(([, v]) => typeof v !== "undefined").map(([key, value]) => { | ||
return (Array.isArray(value) ? value : [value]).map((props) => { | ||
switch (key) { | ||
case "title": | ||
return resolveTag(key, { children: props }, e); | ||
case "titleTemplate": | ||
return { | ||
tag: key, | ||
children: props, | ||
props: {}, | ||
runtime: { entryId: e.id }, | ||
options: e.options | ||
}; | ||
case "base": | ||
@@ -281,3 +287,3 @@ case "meta": | ||
if (template == null) | ||
return ""; | ||
return title || null; | ||
if (typeof template === "function") | ||
@@ -290,3 +296,2 @@ return template(title); | ||
const resolvedEntries = resolveHeadEntries(entries); | ||
const titleTemplate = resolvedEntries.map((i) => i.input.titleTemplate).reverse().find((i) => i != null); | ||
resolvedEntries.forEach((entry, entryIndex) => { | ||
@@ -297,12 +302,31 @@ const tags = headInputToTags(entry); | ||
tag.runtime.position = entryIndex * 1e4 + tagIdx; | ||
if (titleTemplate && tag.tag === "title") { | ||
tag.children = renderTitleTemplate( | ||
titleTemplate, | ||
tag.children | ||
); | ||
} | ||
deduping[tagDedupeKey(tag)] = tag; | ||
}); | ||
}); | ||
return Object.values(deduping).sort((a, b) => a.runtime.position - b.runtime.position).sort(sortTags); | ||
let resolvedTags = Object.values(deduping).sort((a, b) => a.runtime.position - b.runtime.position).sort(sortTags); | ||
const titleTemplateIdx = resolvedTags.findIndex((i) => i.tag === "titleTemplate"); | ||
const titleIdx = resolvedTags.findIndex((i) => i.tag === "title"); | ||
if (titleIdx !== -1 && titleTemplateIdx !== -1) { | ||
const newTitle = renderTitleTemplate( | ||
resolvedTags[titleTemplateIdx].children, | ||
resolvedTags[titleIdx].children | ||
); | ||
if (newTitle !== null) { | ||
resolvedTags[titleIdx].children = newTitle || resolvedTags[titleIdx].children; | ||
} else { | ||
resolvedTags = resolvedTags.filter((_, i) => i !== titleIdx); | ||
} | ||
resolvedTags = resolvedTags.filter((_, i) => i !== titleTemplateIdx); | ||
} else if (titleTemplateIdx !== -1) { | ||
const newTitle = renderTitleTemplate( | ||
resolvedTags[titleTemplateIdx].children | ||
); | ||
if (newTitle !== null) { | ||
resolvedTags[titleTemplateIdx].children = newTitle; | ||
resolvedTags[titleTemplateIdx].tag = "title"; | ||
} else { | ||
resolvedTags = resolvedTags.filter((_, i) => i !== titleTemplateIdx); | ||
} | ||
} | ||
return resolvedTags; | ||
}; | ||
@@ -309,0 +333,0 @@ |
{ | ||
"name": "@vueuse/head", | ||
"version": "1.0.0-rc.6", | ||
"version": "1.0.0-rc.7", | ||
"packageManager": "pnpm@7.5.0", | ||
@@ -46,4 +46,4 @@ "description": "Document head manager for Vue 3. SSR ready.", | ||
"@vueuse/shared": "^9.3.0", | ||
"@zhead/schema": "^0.8.5", | ||
"@zhead/schema-vue": "^0.8.5" | ||
"@zhead/schema": "^0.9.5", | ||
"@zhead/schema-vue": "^0.9.5" | ||
}, | ||
@@ -68,8 +68,8 @@ "devDependencies": { | ||
"pathe": "^0.3.9", | ||
"playwright": "^1.27.0", | ||
"playwright": "^1.27.1", | ||
"simple-git-hooks": "^2.8.0", | ||
"tsup": "^6.2.3", | ||
"typescript": "^4.8.4", | ||
"vite": "^3.1.6", | ||
"vitest": "^0.24.0", | ||
"vite": "^3.1.7", | ||
"vitest": "^0.24.1", | ||
"vue": "^3.2.40", | ||
@@ -76,0 +76,0 @@ "vue-router": "^4.1.5" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60033
1551
+ Added@zhead/schema@0.9.9(transitive)
+ Added@zhead/schema-vue@0.9.9(transitive)
- Removed@zhead/schema@0.8.5(transitive)
- Removed@zhead/schema-raw@0.8.5(transitive)
- Removed@zhead/schema-vue@0.8.5(transitive)
Updated@zhead/schema@^0.9.5
Updated@zhead/schema-vue@^0.9.5