Skip to content

Commit 019106e

Browse files
committed
fix: prioritize source_url over eurl to prevent duplicate links
Signed-off-by: Rishi Raj <rishiraj438gt@gmail.com>
1 parent ce5db95 commit 019106e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/sections/Company/News-single/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,16 @@ const NewsSingle = ({ data, children }) => {
7979
</Row>
8080
</div>
8181
{
82-
frontmatter.eurl && (
82+
frontmatter.source_url ? (
8383
<div style={{ display: "flex" }}>
8484
<h5>
85-
Read the full article on <a href={frontmatter.eurl} target="_blank" rel="noopener noreferrer">{frontmatter.author}</a>
85+
Originally published at <a href={frontmatter.source_url} target="_blank" rel="noopener noreferrer">{frontmatter.source_url}</a>
8686
</h5>
8787
</div>
88-
)
89-
}
90-
{
91-
frontmatter.source_url && (
88+
) : frontmatter.eurl && (
9289
<div style={{ display: "flex" }}>
9390
<h5>
94-
Originally published at <a href={frontmatter.source_url} target="_blank" rel="noopener noreferrer">{frontmatter.source_url}</a>
91+
Read the full article on <a href={frontmatter.eurl} target="_blank" rel="noopener noreferrer">{frontmatter.author}</a>
9592
</h5>
9693
</div>
9794
)

src/sections/Company/News-single/source_url.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,23 @@ describe('NewsSingle', () => {
5757
const wrapper = shallow(<NewsSingle data={data} />);
5858
expect(wrapper.text()).not.toContain('Originally published at');
5959
});
60+
61+
it('does not render "Read the full article on" (eurl) when source_url is present', () => {
62+
const data = {
63+
mdx: {
64+
frontmatter: {
65+
title: 'Test',
66+
source_url: 'https://original.com',
67+
eurl: 'https://eurl.com',
68+
author: 'Me',
69+
date: '2023-01-01'
70+
},
71+
fields: { slug: '/test' }
72+
}
73+
};
74+
75+
const wrapper = shallow(<NewsSingle data={data} />);
76+
expect(wrapper.text()).toContain('Originally published at');
77+
expect(wrapper.text()).not.toContain('Read the full article on');
78+
});
6079
});

0 commit comments

Comments
 (0)