test/node_modules/@vuepress/plugin-seo/lib/node/utils/getAuthor.js
2024-08-13 09:27:52 +08:00

18 lines
713 B
JavaScript

import { isArray, isPlainObject, isString } from '@vuepress/helper';
const isSEOAuthor = (author) => isPlainObject(author) && isString(author.name);
export const getSEOAuthor = (author) => {
if (author) {
if (isArray(author))
return author
.map((item) => isString(item) ? { name: item } : isSEOAuthor(item) ? item : null)
.filter((item) => item !== null);
if (isString(author))
return [{ name: author }];
if (isSEOAuthor(author))
return [author];
console.error(`Expect "author" to be \`AuthorInfo[] | AuthorInfo | string[] | string | undefined\`, but got`, author);
return [];
}
return [];
};