unhead 1.1.21 → 1.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -203,13 +203,11 @@ const EventHandlersPlugin = () => {
203
203
  };
204
204
 
205
205
  const UsesMergeStrategy = ["templateParams", "htmlAttrs", "bodyAttrs"];
206
- const DedupesTagsPlugin = (options) => {
207
- options = options || {};
208
- const dedupeKeys = options.dedupeKeys || ["hid", "vmid", "key"];
206
+ const DedupesTagsPlugin = () => {
209
207
  return shared.defineHeadPlugin({
210
208
  hooks: {
211
209
  "tag:normalise": function({ tag }) {
212
- dedupeKeys.forEach((key) => {
210
+ ["hid", "vmid", "key"].forEach((key) => {
213
211
  if (tag.props[key]) {
214
212
  tag.key = tag.props[key];
215
213
  delete tag.props[key];
@@ -271,25 +269,31 @@ const DedupesTagsPlugin = (options) => {
271
269
  };
272
270
 
273
271
  function processTemplateParams(s, config) {
274
- const sub = (_, token) => {
275
- let val;
276
- if (token === "pageTitle" || token === "s")
272
+ function sub(token) {
273
+ let val = "";
274
+ if (["s", "pageTitle"].includes(token))
277
275
  val = config.pageTitle;
278
276
  else if (token.includes("."))
279
277
  val = token.split(".").reduce((acc, key) => acc[key] || "", config);
280
- else
281
- val = config[token];
282
- return val || "";
283
- };
284
- let template = s.replace(/%(\w+\.+\w+)/g, sub).replace(/%(\w+)/g, sub).trim();
278
+ return val || config[token] || "";
279
+ }
280
+ let decoded = s;
281
+ try {
282
+ decoded = decodeURI(s);
283
+ } catch {
284
+ }
285
+ const tokens = (decoded.match(/%(\w+\.+\w+)|%(\w+)/g) || []).sort().reverse();
286
+ tokens.forEach((token) => {
287
+ s = s.replaceAll(token, sub(token.slice(1))).trim();
288
+ });
285
289
  if (config.separator) {
286
- if (template.endsWith(config.separator))
287
- template = template.slice(0, -config.separator.length).trim();
288
- if (template.startsWith(config.separator))
289
- template = template.slice(config.separator.length).trim();
290
- template = template.replace(new RegExp(`\\${config.separator}\\s*\\${config.separator}`, "g"), config.separator);
290
+ if (s.endsWith(config.separator))
291
+ s = s.slice(0, -config.separator.length).trim();
292
+ if (s.startsWith(config.separator))
293
+ s = s.slice(config.separator.length).trim();
294
+ s = s.replace(new RegExp(`\\${config.separator}\\s*\\${config.separator}`, "g"), config.separator);
291
295
  }
292
- return template;
296
+ return s;
293
297
  }
294
298
  function TemplateParamsPlugin() {
295
299
  return shared.defineHeadPlugin({
package/dist/index.d.ts CHANGED
@@ -30,10 +30,7 @@ declare const ProvideTagHashPlugin: () => _unhead_schema.HeadPlugin;
30
30
  */
31
31
  declare const EventHandlersPlugin: () => _unhead_schema.HeadPlugin;
32
32
 
33
- interface DedupesTagsPluginOptions {
34
- dedupeKeys?: string[];
35
- }
36
- declare const DedupesTagsPlugin: (options?: DedupesTagsPluginOptions) => _unhead_schema.HeadPlugin;
33
+ declare const DedupesTagsPlugin: () => _unhead_schema.HeadPlugin;
37
34
 
38
35
  declare function TemplateParamsPlugin(): _unhead_schema.HeadPlugin;
39
36
 
@@ -187,4 +184,4 @@ declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promi
187
184
 
188
185
  declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<string, string>>>): HeadSafe;
189
186
 
190
- export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
187
+ export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
package/dist/index.mjs CHANGED
@@ -201,13 +201,11 @@ const EventHandlersPlugin = () => {
201
201
  };
202
202
 
203
203
  const UsesMergeStrategy = ["templateParams", "htmlAttrs", "bodyAttrs"];
204
- const DedupesTagsPlugin = (options) => {
205
- options = options || {};
206
- const dedupeKeys = options.dedupeKeys || ["hid", "vmid", "key"];
204
+ const DedupesTagsPlugin = () => {
207
205
  return defineHeadPlugin({
208
206
  hooks: {
209
207
  "tag:normalise": function({ tag }) {
210
- dedupeKeys.forEach((key) => {
208
+ ["hid", "vmid", "key"].forEach((key) => {
211
209
  if (tag.props[key]) {
212
210
  tag.key = tag.props[key];
213
211
  delete tag.props[key];
@@ -269,25 +267,31 @@ const DedupesTagsPlugin = (options) => {
269
267
  };
270
268
 
271
269
  function processTemplateParams(s, config) {
272
- const sub = (_, token) => {
273
- let val;
274
- if (token === "pageTitle" || token === "s")
270
+ function sub(token) {
271
+ let val = "";
272
+ if (["s", "pageTitle"].includes(token))
275
273
  val = config.pageTitle;
276
274
  else if (token.includes("."))
277
275
  val = token.split(".").reduce((acc, key) => acc[key] || "", config);
278
- else
279
- val = config[token];
280
- return val || "";
281
- };
282
- let template = s.replace(/%(\w+\.+\w+)/g, sub).replace(/%(\w+)/g, sub).trim();
276
+ return val || config[token] || "";
277
+ }
278
+ let decoded = s;
279
+ try {
280
+ decoded = decodeURI(s);
281
+ } catch {
282
+ }
283
+ const tokens = (decoded.match(/%(\w+\.+\w+)|%(\w+)/g) || []).sort().reverse();
284
+ tokens.forEach((token) => {
285
+ s = s.replaceAll(token, sub(token.slice(1))).trim();
286
+ });
283
287
  if (config.separator) {
284
- if (template.endsWith(config.separator))
285
- template = template.slice(0, -config.separator.length).trim();
286
- if (template.startsWith(config.separator))
287
- template = template.slice(config.separator.length).trim();
288
- template = template.replace(new RegExp(`\\${config.separator}\\s*\\${config.separator}`, "g"), config.separator);
288
+ if (s.endsWith(config.separator))
289
+ s = s.slice(0, -config.separator.length).trim();
290
+ if (s.startsWith(config.separator))
291
+ s = s.slice(config.separator.length).trim();
292
+ s = s.replace(new RegExp(`\\${config.separator}\\s*\\${config.separator}`, "g"), config.separator);
289
293
  }
290
- return template;
294
+ return s;
291
295
  }
292
296
  function TemplateParamsPlugin() {
293
297
  return defineHeadPlugin({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unhead",
3
3
  "type": "module",
4
- "version": "1.1.21",
4
+ "version": "1.1.23",
5
5
  "packageManager": "pnpm@7.28.0",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
@@ -31,9 +31,9 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "hookable": "^5.4.2",
34
- "@unhead/dom": "1.1.21",
35
- "@unhead/schema": "1.1.21",
36
- "@unhead/shared": "1.1.21"
34
+ "@unhead/dom": "1.1.23",
35
+ "@unhead/schema": "1.1.23",
36
+ "@unhead/shared": "1.1.23"
37
37
  },
38
38
  "devDependencies": {
39
39
  "packrup": "^0.1.0"