Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add A List Apart #12960

Merged
merged 12 commits into from
Aug 10, 2023
62 changes: 62 additions & 0 deletions docs/en/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,68 @@ pageClass: routes

<RouteEn author="nczitzk" example="/acm/amturingaward" path="/acm/amturingaward"/>

## A List Apart

### Articles

<RouteEn author="Rjnishant530" example="/alistapart" path="/alistapart" radar="1"/>

### Topics

<RouteEn author="Rjnishant530" example="/alistapart/application-development" path="/alistapart/:topic" :paramsDesc="['Any Topic or from the table below. Defaults to All Articles']" radar="1"/>

You have the option to utilize the main heading or use individual categories as topics for the path.

Topics :

| **Code** | _code_ |
|-------------------------|-------------------------|
| **Application Development** | _application-development_ |
| **Browsers** | _browsers_ |
| **CSS** | _css_ |
| **HTML** | _html_ |
| **JavaScript** | _javascript_ |
| **The Server Side** | _the-server-side_ |

| **Content** | _content_ |
|-------------------------|-------------------------|
| **Community** | _community_ |
| **Content Strategy** | _content-strategy_ |
| **Writing** | _writing_ |

| **Design** | _design_ |
|-------------------------|-------------------------|
| **Brand Identity** | _brand-identity_ |
| **Graphic Design** | _graphic-design_ |
| **Layout & Grids** | _layout-grids_ |
| **Mobile/Multidevice** | _mobile-multidevice_ |
| **Responsive Design** | _responsive-design_ |
| **Typography & Web Fonts** | _typography-web-fonts_ |

| **Industry & Business** | _industry-business_ |
|-------------------------|-------------------------|
| **Business** | _business_ |
| **Career** | _career_ |
| **Industry** | _industry_ |
| **State of the Web** | _state-of-the-web_ |

| **Process** | _process_ |
|-------------------------|-------------------------|
| **Creativity** | _creativity_ |
| **Project Management** | _project-management_ |
| **Web Strategy** | _web-strategy_ |
| **Workflow & Tools** | _workflow-tools_ |

| **User Experience** | _user-experience_ |
|-------------------------|-------------------------|
| **Accessibility** | _accessibility_ |
| **Information Architecture** | _information-architecture_ |
| **Interaction Design** | _interaction-design_ |
| **Usability** | _usability_ |
| **User Research** | _user-research_ |

</RouteEn>

## AtCoder

### Present Contests
Expand Down
30 changes: 30 additions & 0 deletions lib/v2/alistapart/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { getData, getList } = require('./utils');

module.exports = async (ctx) => {
const baseUrl = 'https://alistapart.com';
const route = '/wp-json/wp/v2/article';

const data = await getData(`${baseUrl}${route}`);
const listItems = await getList(data);
const items = await Promise.all(
listItems.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const category = await getData(`https://alistapart.com/wp-json/wp/v2/categories?post=${item.id}`);
item.category = category.map((v) => v.name);
const author = await getData(`https://alistapart.com/wp-json/wp/v2/coauthors?post=${item.id}`);
item.author = author.map((v) => v.name).join(', ');
return item;
})
)
);

ctx.state.data = {
title: 'A List Apart',
link: `${baseUrl}/articles`,
item: items,
description: 'Articles on aListApart.com',
logo: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=192,192&ssl=1',
icon: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=32,32&ssl=1',
language: 'en-us',
};
};
4 changes: 4 additions & 0 deletions lib/v2/alistapart/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/': ['Rjnishant530'],
'/:topic?': ['Rjnishant530'],
};
19 changes: 19 additions & 0 deletions lib/v2/alistapart/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'alistapart.com': {
_name: 'A List Apart',
'.': [
{
title: 'Articles',
docs: 'https://docs.rsshub.app/en/programming.html#a-list-apart',
source: ['/articles/'],
target: '/alistapart',
},
{
title: 'Topics',
docs: 'https://docs.rsshub.app/en/programming.html#a-list-apart',
source: ['/blog/topic/:topic'],
target: '/alistapart/:topic',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/alistapart/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/', require('./index'));
router.get('/:topic', require('./topic'));
};
32 changes: 32 additions & 0 deletions lib/v2/alistapart/topic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { getData, getList } = require('./utils');

module.exports = async (ctx) => {
const baseUrl = 'https://alistapart.com';
const searchRoute = '/wp-json/wp/v2/categories?search=';
Rjnishant530 marked this conversation as resolved.
Show resolved Hide resolved
const articleRoute = '/wp-json/wp/v2/article?categories=';
const { topic } = ctx.params;
const id = (await getData(`${baseUrl}${searchRoute}${topic}`))[0].id;
const data = await getData(`${baseUrl}${articleRoute}${id}`);
const listItems = await getList(data);
const items = await Promise.all(
listItems.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const category = await getData(`https://alistapart.com/wp-json/wp/v2/categories?post=${item.id}`);
item.category = category.map((v) => v.name);
const author = await getData(`https://alistapart.com/wp-json/wp/v2/coauthors?post=${item.id}`);
item.author = author.map((v) => v.name).join(', ');
return item;
})
)
);
Rjnishant530 marked this conversation as resolved.
Show resolved Hide resolved

ctx.state.data = {
title: 'A List Apart',
link: `${baseUrl}/blog/topic/${topic}`,
item: items,
description: `${topic[0].toUpperCase() + topic.slice(1)} Articles on aListApart.com`,
logo: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=192,192&ssl=1',
icon: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=32,32&ssl=1',
language: 'en-us',
};
};
20 changes: 20 additions & 0 deletions lib/v2/alistapart/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

const getData = (url) => got.get(url).json();

const getList = (data) =>
data.map((value) => {
const { id, title, content, date_gmt, modified_gmt, link } = value;
return {
id,
title: title.rendered,
description: content.rendered,
link,
pubDate: timezone(parseDate(date_gmt), 0),
updated: timezone(parseDate(modified_gmt), 0),
};
});

module.exports = { getData, getList };