Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
Expand Down
9 changes: 9 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface ILinkPreviewResponse {
url: string;
title: string;
siteName: string | undefined;
author: string | undefined;
description: string | undefined;
mediaType: string;
contentType: string | undefined;
Expand Down Expand Up @@ -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`) ||
Expand Down Expand Up @@ -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),
Expand Down
Loading