@unhead/schema-org 0.4.0 → 0.5.0

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
@@ -6,10 +6,17 @@ function defineSchemaOrgResolver(schema) {
6
6
  return schema;
7
7
  }
8
8
 
9
- const PROTOCOL_REGEX = /^\w{2,}:(\/\/)?/;
10
- const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
11
- function hasProtocol(inputString, acceptProtocolRelative = false) {
12
- return PROTOCOL_REGEX.test(inputString) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputString);
9
+ const PROTOCOL_STRICT_REGEX = /^\w{2,}:([/\\]{1,2})/;
10
+ const PROTOCOL_REGEX = /^\w{2,}:([/\\]{2})?/;
11
+ const PROTOCOL_RELATIVE_REGEX = /^[/\\]{2}[^/\\]+/;
12
+ function hasProtocol(inputString, opts = {}) {
13
+ if (typeof opts === "boolean") {
14
+ opts = { acceptRelative: opts };
15
+ }
16
+ if (opts.strict) {
17
+ return PROTOCOL_STRICT_REGEX.test(inputString);
18
+ }
19
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
13
20
  }
14
21
  const TRAILING_SLASH_RE = /\/$|\/\?/;
15
22
  function hasTrailingSlash(input = "", queryParameters = false) {
@@ -176,7 +183,7 @@ const offerResolver = defineSchemaOrgResolver({
176
183
  },
177
184
  resolve(node, ctx) {
178
185
  setIfEmpty(node, "priceCurrency", ctx.meta.currency);
179
- setIfEmpty(node, "priceValidUntil", new Date(Date.UTC(new Date().getFullYear() + 1, 12, -1, 0, 0, 0)));
186
+ setIfEmpty(node, "priceValidUntil", new Date(Date.UTC((/* @__PURE__ */ new Date()).getFullYear() + 1, 12, -1, 0, 0, 0)));
180
187
  if (node.url)
181
188
  resolveWithBase(ctx.meta.host, node.url);
182
189
  if (node.availability)
@@ -321,6 +328,7 @@ const imageResolver = defineSchemaOrgResolver({
321
328
  "@type": "ImageObject"
322
329
  },
323
330
  inheritMeta: [
331
+ // @todo possibly only do if there's a caption
324
332
  "inLanguage"
325
333
  ],
326
334
  idPrefix: "host",
@@ -1821,7 +1829,7 @@ function SchemaOrgUnheadPlugin(config, meta) {
1821
1829
  tag.tagPosition = config.tagPosition === "head" ? "head" : "bodyClose";
1822
1830
  }
1823
1831
  if (tag.tag === "title")
1824
- resolvedMeta.title = tag.children;
1832
+ resolvedMeta.title = tag.textContent;
1825
1833
  else if (tag.tag === "meta" && tag.props.name === "description")
1826
1834
  resolvedMeta.description = tag.props.content;
1827
1835
  else if (tag.tag === "link" && tag.props.rel === "canonical")
@@ -1832,7 +1840,7 @@ function SchemaOrgUnheadPlugin(config, meta) {
1832
1840
  "tags:resolve": async function(ctx) {
1833
1841
  for (const tag of ctx.tags) {
1834
1842
  if (tag.tag === "script" && tag.key === "schema-org-graph") {
1835
- tag.children = JSON.stringify({
1843
+ tag.innerHTML = JSON.stringify({
1836
1844
  "@context": "https://schema.org",
1837
1845
  "@graph": graph.resolveGraph({ ...config, ...resolvedMeta, ...await meta() })
1838
1846
  }, null, 2);
package/dist/index.d.ts CHANGED
@@ -990,7 +990,7 @@ interface JobPostingSimple extends Thing {
990
990
  /**
991
991
  * Type of employment
992
992
  */
993
- employmentType?: 'FULL_TIME' | 'PART_TIME' | 'CONTRACTOR' | 'TEMPORARY' | 'INTERN' | 'VOLUNTEER' | 'PER_DIEM' | 'OTHER';
993
+ employmentType?: EmploymentType | EmploymentType[];
994
994
  /**
995
995
  * The date when the job posting will expire in ISO 8601 format. For example, "2017-02-24"
996
996
  * or "2017-02-24T19:33:17+00:00".
@@ -1008,6 +1008,7 @@ interface JobPostingSimple extends Thing {
1008
1008
  interface JobPosting extends JobPostingSimple {
1009
1009
  }
1010
1010
  declare const jobPostingResolver: SchemaOrgNodeDefinition<JobPosting>;
1011
+ type EmploymentType = 'FULL_TIME' | 'PART_TIME' | 'CONTRACTOR' | 'TEMPORARY' | 'INTERN' | 'VOLUNTEER' | 'PER_DIEM' | 'OTHER';
1011
1012
 
1012
1013
  type DayOfWeek = 'Friday' | 'Monday' | 'PublicHolidays' | 'Saturday' | 'Sunday' | 'Thursday' | 'Tuesday' | 'Wednesday';
1013
1014
  type Time = `${number}${number}:${number}${number}`;
package/dist/index.mjs CHANGED
@@ -4,10 +4,17 @@ function defineSchemaOrgResolver(schema) {
4
4
  return schema;
5
5
  }
6
6
 
7
- const PROTOCOL_REGEX = /^\w{2,}:(\/\/)?/;
8
- const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
9
- function hasProtocol(inputString, acceptProtocolRelative = false) {
10
- return PROTOCOL_REGEX.test(inputString) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputString);
7
+ const PROTOCOL_STRICT_REGEX = /^\w{2,}:([/\\]{1,2})/;
8
+ const PROTOCOL_REGEX = /^\w{2,}:([/\\]{2})?/;
9
+ const PROTOCOL_RELATIVE_REGEX = /^[/\\]{2}[^/\\]+/;
10
+ function hasProtocol(inputString, opts = {}) {
11
+ if (typeof opts === "boolean") {
12
+ opts = { acceptRelative: opts };
13
+ }
14
+ if (opts.strict) {
15
+ return PROTOCOL_STRICT_REGEX.test(inputString);
16
+ }
17
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
11
18
  }
12
19
  const TRAILING_SLASH_RE = /\/$|\/\?/;
13
20
  function hasTrailingSlash(input = "", queryParameters = false) {
@@ -174,7 +181,7 @@ const offerResolver = defineSchemaOrgResolver({
174
181
  },
175
182
  resolve(node, ctx) {
176
183
  setIfEmpty(node, "priceCurrency", ctx.meta.currency);
177
- setIfEmpty(node, "priceValidUntil", new Date(Date.UTC(new Date().getFullYear() + 1, 12, -1, 0, 0, 0)));
184
+ setIfEmpty(node, "priceValidUntil", new Date(Date.UTC((/* @__PURE__ */ new Date()).getFullYear() + 1, 12, -1, 0, 0, 0)));
178
185
  if (node.url)
179
186
  resolveWithBase(ctx.meta.host, node.url);
180
187
  if (node.availability)
@@ -319,6 +326,7 @@ const imageResolver = defineSchemaOrgResolver({
319
326
  "@type": "ImageObject"
320
327
  },
321
328
  inheritMeta: [
329
+ // @todo possibly only do if there's a caption
322
330
  "inLanguage"
323
331
  ],
324
332
  idPrefix: "host",
@@ -1819,7 +1827,7 @@ function SchemaOrgUnheadPlugin(config, meta) {
1819
1827
  tag.tagPosition = config.tagPosition === "head" ? "head" : "bodyClose";
1820
1828
  }
1821
1829
  if (tag.tag === "title")
1822
- resolvedMeta.title = tag.children;
1830
+ resolvedMeta.title = tag.textContent;
1823
1831
  else if (tag.tag === "meta" && tag.props.name === "description")
1824
1832
  resolvedMeta.description = tag.props.content;
1825
1833
  else if (tag.tag === "link" && tag.props.rel === "canonical")
@@ -1830,7 +1838,7 @@ function SchemaOrgUnheadPlugin(config, meta) {
1830
1838
  "tags:resolve": async function(ctx) {
1831
1839
  for (const tag of ctx.tags) {
1832
1840
  if (tag.tag === "script" && tag.key === "schema-org-graph") {
1833
- tag.children = JSON.stringify({
1841
+ tag.innerHTML = JSON.stringify({
1834
1842
  "@context": "https://schema.org",
1835
1843
  "@graph": graph.resolveGraph({ ...config, ...resolvedMeta, ...await meta() })
1836
1844
  }, null, 2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unhead/schema-org",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "packageManager": "pnpm@7.8.0",
5
5
  "description": "Node Schema.org for Simple and Automated Google Rich Results",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
@@ -34,11 +34,11 @@
34
34
  "dist"
35
35
  ],
36
36
  "peerDependencies": {
37
- "unhead": ">=1.0.10"
37
+ "unhead": ">=1.1.9"
38
38
  },
39
39
  "devDependencies": {
40
- "ufo": "^1.0.1",
41
- "unhead": "^1.0.14"
40
+ "ufo": "^1.1.0",
41
+ "unhead": "^1.1.9"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild .",