File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff 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 `
Original file line number Diff line number Diff 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+
7785function 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 ) ,
You can’t perform that action at this time.
0 commit comments