-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(meta): merge head at runtime (#363)
* refactor: remove spa workaround * refactor: merge meta in runtime * refactor: SPA support * fix spa support * docs: recommand using buildModules * feat: warn when target is function * docs: add note about ssr: false
- Loading branch information
Showing
10 changed files
with
197 additions
and
118 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 @@ | ||
<%= JSON.stringify(options.head, null, 2) %> |
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,36 @@ | ||
exports.mergeMeta = function mergeMeta (to, from) { | ||
if (typeof to === 'function') { | ||
// eslint-disable-next-line no-console | ||
console.warn('Cannot merge meta. Avoid using head as a function!') | ||
return | ||
} | ||
|
||
for (const key in from) { | ||
const value = from[key] | ||
if (Array.isArray(value)) { | ||
to[key] = to[key] || [] | ||
for (const item of value) { | ||
// Avoid duplicates | ||
if ( | ||
(item.hid && hasMeta(to[key], 'hid', item.hid)) || | ||
(item.name && hasMeta(to[key], 'name', item.name)) | ||
) { | ||
continue | ||
} | ||
// Add meta | ||
to[key].push(item) | ||
} | ||
} else if (typeof value === 'object') { | ||
to[key] = to[key] || {} | ||
for (const attr in value) { | ||
to[key][attr] = value[attr] | ||
} | ||
} else if (to[key] === undefined) { | ||
to[key] = value | ||
} | ||
} | ||
} | ||
|
||
function hasMeta (arr, key, val) { | ||
return arr.find(obj => val ? obj[key] === val : obj[key]) | ||
} |
Oops, something went wrong.