diff --git a/__tests__/index.spec.ts b/__tests__/index.spec.ts index c792372..8d6da2d 100644 --- a/__tests__/index.spec.ts +++ b/__tests__/index.spec.ts @@ -31,6 +31,14 @@ describe(`#getLinkPreview()`, () => { expect(linkInfo.charset?.toLowerCase()).toEqual(`utf-8`); }); + it("should extract author from news article", async () => { + const linkInfo: any = await getLinkPreview( + `https://www.usatoday.com/story/special/contributor-content/2025/10/15/why-chaos-engineering-is-more-important-than-ever-in-the-ai-era/86712877007/` + ); + + expect(linkInfo.author).toEqual(`Matt Emma`); + }) + it(`should extract link info from a URL with a newline`, async () => { const linkInfo: any = await getLinkPreview( ` diff --git a/index.ts b/index.ts index 1e044ae..5859614 100644 --- a/index.ts +++ b/index.ts @@ -6,6 +6,7 @@ interface ILinkPreviewResponse { url: string; title: string; siteName: string | undefined; + author: string | undefined; description: string | undefined; mediaType: string; contentType: string | undefined; @@ -74,6 +75,13 @@ function getSiteName(doc: cheerio.Root) { return siteName; } +function getAuthor(doc: cheerio.Root) { + const author = + metaTagContent(doc, `author`, `name`) || + metaTagContent(doc, `article:author`, `property`); + return author; +} + function getDescription(doc: cheerio.Root) { const description = metaTagContent(doc, `description`, `name`) || @@ -301,6 +309,7 @@ function parseTextResponse( title: getTitle(doc), siteName: getSiteName(doc), description: getDescription(doc), + author: getAuthor(doc), mediaType: getMediaType(doc) || `website`, contentType, images: getImages(doc, url, options.imagesPropertyType),