Skip to content

Commit

Permalink
chore: minor ts improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Nov 1, 2023
1 parent 8c0ce98 commit 21f1473
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/schema-org/src/core/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { asArray, idReference, prefixId, setIfEmpty, stripEmptyProperties } from
import { loadResolver } from '../resolver'
import type { SchemaOrgGraph } from './graph'

export function resolveMeta(meta: MetaInput) {
export function resolveMeta(meta: Partial<MetaInput>) {
if (!meta.host && meta.canonicalHost)
meta.host = meta.canonicalHost
if (!meta.tagPosition && meta.position)
Expand Down
7 changes: 4 additions & 3 deletions packages/schema-org/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export function UnheadSchemaOrg(options?: PluginSchemaOrgOptions) {
* @deprecated Providing a plugin is no longer required. You can remove this code.
*/
export function PluginSchemaOrg(options?: PluginSchemaOrgOptions & { resolveMeta?: () => Record<string, any> }) {
const fallback = () => ({})
const fallback = () => ({} as Partial<MetaInput>)
return SchemaOrgUnheadPlugin({} as MetaInput, options?.resolveMeta || fallback, options)
}

/**
* @deprecated Providing a plugin is no longer required. You can remove this code.
*/
export function SchemaOrgUnheadPlugin(config: MetaInput, meta: () => Record<string, any>, options?: PluginSchemaOrgOptions) {
export function SchemaOrgUnheadPlugin(config: MetaInput, meta: () => Partial<MetaInput> | Promise<Partial<MetaInput>>, options?: PluginSchemaOrgOptions) {
config = resolveMeta({ ...config })
let graph: SchemaOrgGraph
let resolvedMeta = {} as ResolvedMeta
Expand Down Expand Up @@ -76,7 +76,7 @@ export function SchemaOrgUnheadPlugin(config: MetaInput, meta: () => Record<stri
}
},
'tags:resolve': async function (ctx) {
// find the schema.org node
// find the schema.org node, should be a single instance
for (const tag of ctx.tags) {
if (tag.tag === 'script' && tag.key === 'schema-org-graph') {
const minify = options?.minify || process.env.NODE_ENV === 'production'
Expand All @@ -85,6 +85,7 @@ export function SchemaOrgUnheadPlugin(config: MetaInput, meta: () => Record<stri
'@graph': graph.resolveGraph({ ...config, ...resolvedMeta, ...(await meta?.() || {}) }),
}, null, minify ? 0 : 2)
delete tag.props.nodes
return
}
}
},
Expand Down

0 comments on commit 21f1473

Please sign in to comment.