Skip to content

Commit 2dc94e8

Browse files
authored
Merge pull request #173 from Alpha4615/add-author-tag-support
2 parents 414133c + 31fea34 commit 2dc94e8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

__tests__/index.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ describe(`#getLinkPreview()`, () => {
3131
expect(linkInfo.charset?.toLowerCase()).toEqual(`utf-8`);
3232
});
3333

34+
it("should extract author from news article", async () => {
35+
const linkInfo: any = await getLinkPreview(
36+
`https://www.usatoday.com/story/special/contributor-content/2025/10/15/why-chaos-engineering-is-more-important-than-ever-in-the-ai-era/86712877007/`
37+
);
38+
39+
expect(linkInfo.author).toEqual(`Matt Emma`);
40+
})
41+
3442
it(`should extract link info from a URL with a newline`, async () => {
3543
const linkInfo: any = await getLinkPreview(
3644
`

index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface ILinkPreviewResponse {
66
url: string;
77
title: string;
88
siteName: string | undefined;
9+
author: string | undefined;
910
description: string | undefined;
1011
mediaType: string;
1112
contentType: string | undefined;
@@ -74,6 +75,13 @@ function getSiteName(doc: cheerio.Root) {
7475
return siteName;
7576
}
7677

78+
function getAuthor(doc: cheerio.Root) {
79+
const author =
80+
metaTagContent(doc, `author`, `name`) ||
81+
metaTagContent(doc, `article:author`, `property`);
82+
return author;
83+
}
84+
7785
function getDescription(doc: cheerio.Root) {
7886
const description =
7987
metaTagContent(doc, `description`, `name`) ||
@@ -301,6 +309,7 @@ function parseTextResponse(
301309
title: getTitle(doc),
302310
siteName: getSiteName(doc),
303311
description: getDescription(doc),
312+
author: getAuthor(doc),
304313
mediaType: getMediaType(doc) || `website`,
305314
contentType,
306315
images: getImages(doc, url, options.imagesPropertyType),

0 commit comments

Comments
 (0)