2020-01-18 22:47:48 +04:00
|
|
|
import guides from 'content/guides';
|
|
|
|
import authors from 'content/authors';
|
|
|
|
import siteConfig from 'content/site';
|
2019-11-06 22:10:25 +04:00
|
|
|
|
2019-11-08 18:57:57 +04:00
|
|
|
export const getAllGuides = () => {
|
2019-11-13 21:54:31 +04:00
|
|
|
return guides.filter(guide => !guide.draft)
|
|
|
|
.sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getFeaturedGuides = () => {
|
|
|
|
return getAllGuides().filter(guide => guide.featured);
|
2019-11-08 18:57:57 +04:00
|
|
|
};
|
|
|
|
|
2019-11-06 18:20:09 +04:00
|
|
|
export const getRequestedGuide = req => {
|
2019-11-06 21:37:16 +04:00
|
|
|
const guide = guides.find(guide => guide.url === req.url);
|
2019-11-06 18:20:09 +04:00
|
|
|
if (!guide) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return {
|
|
|
|
...guide,
|
2019-11-06 22:10:25 +04:00
|
|
|
author: authors.find(author => author.username === guide.author) || {},
|
2019-11-06 18:20:09 +04:00
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
2019-11-06 22:10:25 +04:00
|
|
|
|
|
|
|
export const getContributionUrl = (guide) => {
|
2019-11-08 16:47:21 +04:00
|
|
|
return `${siteConfig.url.repoData}${guide.url}.md`
|
2019-11-06 22:10:25 +04:00
|
|
|
};
|