Skip to content

Commit a49201e

Browse files
committed
feat: Add 'source_url' to news articles for original source attribution, display, and documentation, along with corresponding tests
Signed-off-by: Rishi Raj <rishiraj438gt@gmail.com>
1 parent 4d8673d commit a49201e

6 files changed

Lines changed: 74 additions & 2 deletions

File tree

.github/ISSUE_TEMPLATE/news.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ We're in the news! When this happens, we take a moment to reprint that news in o
1111
#### Task
1212
1. Create a copy of the [news template](https://github.com/layer5io/layer5/tree/master/src/collections/news/news-template/0000-00-00-news-title).
1313
1. Follow the instructions included in the news template and rename the new file after the title of the news article using lowercase, kebab casing.
14-
1. Understand that this is a reprint request and that you are to copy/paste the published article verbatim. Be sure that you have included the filled in each of the front matter of properties. And have provided a hero image from the original article as well as that you use the original article authors name.
14+
1. Understand that this is a reprint request and that you are to copy/paste the published article verbatim. Be sure that you have included the filled in each of the front matter of properties. And have provided a hero image from the original article as well as that you use the original article authors name. Use the `source_url` field to point to the original article for attribution.
1515
1. Please add the following article to [src/collections/news](https://github.com/layer5io/layer5/tree/master/src/collections/news):
1616

1717
**Article:**

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ If you'd like to contribute a post to layer5.io/blog, please open an Issue and s
125125

126126
## Adding News
127127

128-
1. In order to add/update news items, see the detailed instructions in the [news issue template](https://github.com/layer5io/layer5/issues/new?template=news.md).
128+
1. In order to add/update news items, see the detailed instructions in the [news issue template](https://github.com/layer5io/layer5/issues/new?template=news.md). When adding a reprint, use the optional `source_url` field in the frontmatter to link back to the original article for attribution.
129129

130130
# Contributing to Layer5's Sistent
131131

src/collections/news/news-template/0000-00-00-news-title/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ author: The Newsroom
66
thumbnail_svg: ./sample.svg
77
darkthumbnail_svg: ./sample.svg
88
eurl: https://www.example.com/some/other/site
9+
source_url: https://original-source.com/article
910
published: false
1011
---
1112

1213
{/* A template and instructions for creating news entries.
1314
1415
subtitle: If the "subtitle" variable is not defined, then put subtitle:""
1516
eurl: If the "eurl" (external url) variable is not defined, then put eurl:""
17+
source_url: Optional. URL to the original article for "Originally published at" attribution.
1618
for any content to be directly entered below the front matter.
1719
published: "true" when ready to be public
1820

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ const NewsSingle = ({ data, children }) => {
8787
</div>
8888
)
8989
}
90+
{
91+
frontmatter.source_url && (
92+
<div style={{ display: "flex" }}>
93+
<h5>
94+
Originally published at <a href={frontmatter.source_url} target="_blank" rel="noopener noreferrer">{frontmatter.source_url}</a>
95+
</h5>
96+
</div>
97+
)
98+
}
9099
<RelatedPosts
91100
postType="news"
92101
relatedPosts={relatedPosts}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import NewsSingle from './index';
4+
import * as Gatsby from 'gatsby';
5+
6+
const useStaticQuery = jest.spyOn(Gatsby, 'useStaticQuery');
7+
const mockUseStyledDarkMode = jest.fn();
8+
9+
jest.mock('../../../theme/app/useStyledDarkMode', () => ({
10+
useStyledDarkMode: () => ({ isDark: false }),
11+
}));
12+
13+
describe('NewsSingle', () => {
14+
beforeEach(() => {
15+
useStaticQuery.mockImplementation(() => ({
16+
allMdx: {
17+
nodes: []
18+
}
19+
}));
20+
});
21+
22+
afterEach(() => {
23+
jest.clearAllMocks();
24+
});
25+
26+
it('renders "Originally published at" link when source_url is present', () => {
27+
const data = {
28+
mdx: {
29+
frontmatter: {
30+
title: 'Test',
31+
source_url: 'https://original.com',
32+
author: 'Me',
33+
date: '2023-01-01'
34+
},
35+
fields: { slug: '/test' }
36+
}
37+
};
38+
39+
const wrapper = shallow(<NewsSingle data={data} />);
40+
const link = wrapper.find('a[href="https://original.com"]');
41+
expect(link.exists()).toBe(true);
42+
expect(wrapper.text()).toContain('Originally published at');
43+
});
44+
45+
it('does not render "Originally published at" link when source_url is missing', () => {
46+
const data = {
47+
mdx: {
48+
frontmatter: {
49+
title: 'Test',
50+
author: 'Me',
51+
date: '2023-01-01'
52+
},
53+
fields: { slug: '/test' }
54+
}
55+
};
56+
57+
const wrapper = shallow(<NewsSingle data={data} />);
58+
expect(wrapper.text()).not.toContain('Originally published at');
59+
});
60+
});

src/templates/news-single.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const query = graphql`
1515
date(formatString: "MMMM Do, YYYY")
1616
author
1717
eurl
18+
source_url
1819
description
1920
presskit
2021
thumbnail {

0 commit comments

Comments
 (0)