Skip to content

Commit

Permalink
add numeral to view level
Browse files Browse the repository at this point in the history
  • Loading branch information
im6 committed May 2, 2020
1 parent 39a1718 commit f4f7891
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 21 deletions.
15 changes: 4 additions & 11 deletions src/collect/task/crawler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import async from 'async';
import numeral from 'numeral';
import cheerio from 'cheerio';
import rp from 'request-promise';
import ProgressBar from 'progress';
Expand All @@ -8,7 +7,6 @@ import sqlExecOne from '../mysqlConnection';
import {
githubUrl,
crawlerTimeout as timeout,
crawlerShowFullNumber,
abusePauseTimeout,
crawlerStepDelay,
crawlerStepNum,
Expand All @@ -32,15 +30,10 @@ const getNum = (obj0, cb) => {
.then(($) => {
const elems = $('a.social-count.js-social-count');
const starElem = elems[1];
if (crawlerShowFullNumber) {
const numLabel = starElem.attribs['aria-label'];
const numStr = numLabel.split(' ')[0];
const num = numeral(numStr).format('0,0');
obj.star = num;
} else {
const num = starElem.children[0].data.trim();
obj.star = num;
}

const numLabel = starElem.attribs['aria-label'];
const numStr = numLabel.split(' ')[0];
obj.star = parseInt(numStr, 10);

if (!obj.name) {
[, obj.name] = obj.github.split('/');
Expand Down
3 changes: 1 addition & 2 deletions src/collect/task/git.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import async from 'async';
import numeral from 'numeral';
import groupBy from 'lodash.groupby';
import orderBy from 'lodash.orderby';
import getPackageList from './crawler';
Expand All @@ -12,7 +11,7 @@ const convertGroupIcon = (data) =>
}, {});

const group = (data, iconMap) => {
const data1 = orderBy(data, (v) => numeral(v.star).value(), 'desc');
const data1 = orderBy(data, (v) => v.star, 'desc');
const data2 = groupBy(data1, 'group');
const data3 = Object.keys(data2);
const result = data3.map((k) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ describe('render properly', () => {
const { getByText, rerender } = render(
<Footer
author={authorName}
year={1998}
year="1998"
hideAuthor
pageSpeedUrl={pageSpeedUrl}
/>
);
rerender(
<Footer author={authorName} year={1998} pageSpeedUrl={pageSpeedUrl} />
<Footer author={authorName} year="1998" pageSpeedUrl={pageSpeedUrl} />
);
expect(getByText(authorName)).toBeTruthy();
});
Expand Down
7 changes: 5 additions & 2 deletions src/components/GitBox/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import numeral from 'numeral';
import style from './style.less';

const GitBox = ({ name, url, img, imgSrc, star, lazyImg }) => (
Expand All @@ -8,7 +9,9 @@ const GitBox = ({ name, url, img, imgSrc, star, lazyImg }) => (
<img src={`${imgSrc}/${img}`} alt={name} data-i={lazyImg} />
<div className={style.rightText}>
<h3>{name}</h3>
<a href={url}>&#9733; {star}</a>
<a href={url} aria-label={`${star} users starred this repository`}>
&#9733; {numeral(star).format('0,0')}
</a>
</div>
</div>
</div>
Expand All @@ -19,7 +22,7 @@ GitBox.propTypes = {
name: PropTypes.string.isRequired,
img: PropTypes.string.isRequired,
imgSrc: PropTypes.string,
star: PropTypes.string.isRequired,
star: PropTypes.number.isRequired,
lazyImg: PropTypes.string,
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/GitBox/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('render properly', () => {
name={name}
img="news"
imgSrc="news"
star="123"
star={123}
/>
);
expect(getAllByText(name)).toHaveLength(1);
Expand Down
1 change: 0 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,5 @@ export const criticalCssPath = {
// crawler config
export const crawlerTimeout = 5 * 1000;
export const abusePauseTimeout = 30 * 1000;
export const crawlerShowFullNumber = true;
export const crawlerStepDelay = 2000;
export const crawlerStepNum = 5;
4 changes: 2 additions & 2 deletions src/pages/GitPage/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ describe('render properly', () => {
desc: 'vue desc',
img: 'vue.png',
imgSrc: '/',
star: '40',
star: 39,
},
{
name: 'react',
github: '/react',
desc: 'vue desc',
imgSrc: '/',
star: '40',
star: 41,
},
],
},
Expand Down

0 comments on commit f4f7891

Please sign in to comment.