2018-06-09 16:08:57 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const dayjs = require('dayjs');
|
2018-06-09 19:51:40 +02:00
|
|
|
const icons = require('./icons');
|
|
|
|
|
|
|
|
const getLatestFilename = fs.readFileSync('data/latest', 'utf-8');
|
|
|
|
console.log(getLatestFilename);
|
|
|
|
const metaData = require(`./${getLatestFilename}`); // eslint-disable-line import/no-dynamic-require
|
2018-06-09 16:08:57 +02:00
|
|
|
|
|
|
|
process.env.NODE_ENV = 'production';
|
|
|
|
|
|
|
|
process.on('unhandledRejection', error => {
|
|
|
|
console.log('unhandledRejection', error.message);
|
|
|
|
});
|
|
|
|
|
|
|
|
// const table = 'data/table.md';
|
|
|
|
const templateHTML = 'website/table.tmpl.html';
|
|
|
|
// const merged = 'website/table.html';
|
|
|
|
const destination = 'website/table.html';
|
|
|
|
|
|
|
|
const valueNames = [
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'homepage',
|
|
|
|
'star',
|
|
|
|
'updated',
|
|
|
|
'language',
|
|
|
|
'license',
|
|
|
|
'author',
|
|
|
|
];
|
|
|
|
|
|
|
|
const getLastUpdate = updated => {
|
|
|
|
const updt = Number(dayjs(updated).diff(dayjs(), 'days'));
|
|
|
|
if (updt < 0) {
|
|
|
|
if (Math.abs(updt) === 1) return `1 day ago`;
|
|
|
|
return `${Math.abs(updt)} days ago`;
|
|
|
|
} else if (updt === 0) return 'today';
|
|
|
|
return updated;
|
|
|
|
};
|
|
|
|
|
|
|
|
const formatEntry = (
|
|
|
|
{
|
|
|
|
name,
|
|
|
|
html_url: repoURL,
|
|
|
|
description,
|
|
|
|
homepage,
|
|
|
|
stargazers_count: stargazers,
|
|
|
|
updated_at: updated,
|
|
|
|
language,
|
|
|
|
license,
|
|
|
|
owner,
|
|
|
|
},
|
|
|
|
i,
|
|
|
|
) =>
|
|
|
|
[
|
|
|
|
`<li data-id="${i}">`,
|
|
|
|
`<a href="${repoURL}" class="link ${valueNames[0]}">${name}</a>`,
|
|
|
|
`<p class="${valueNames[1]}">${description || '-'}</p>`,
|
2018-06-09 18:28:06 +02:00
|
|
|
`<p class="${
|
|
|
|
valueNames[4]
|
|
|
|
} timestamp" data-timestamp="${updated}">Last update: ${getLastUpdate(
|
|
|
|
updated,
|
|
|
|
)}</p>`,
|
2018-06-09 16:08:57 +02:00
|
|
|
(homepage &&
|
|
|
|
`<a href="${homepage}" class="link ${valueNames[2]}">🔗 website</a>`) ||
|
|
|
|
'<p></p>',
|
|
|
|
`<p class="${
|
|
|
|
valueNames[3]
|
|
|
|
} timestamp" data-timestamp="${stargazers}">⭐️${stargazers}</p>`,
|
2018-06-09 18:28:06 +02:00
|
|
|
(language &&
|
|
|
|
`<p class="${valueNames[5]}">${icons[language] ||
|
|
|
|
'💻'}${language}</p>`) ||
|
|
|
|
'<p></p>',
|
2018-06-09 16:08:57 +02:00
|
|
|
(license &&
|
2018-06-09 18:28:06 +02:00
|
|
|
`<a href="${license.url}" class="link ${valueNames[6]}">📃 ${
|
2018-06-09 16:08:57 +02:00
|
|
|
license.name
|
|
|
|
}</a>`) ||
|
|
|
|
'<p></p>',
|
|
|
|
owner &&
|
2018-06-09 18:28:06 +02:00
|
|
|
`<p>Made by </p><a href="${owner.html_url}" class="link ${
|
|
|
|
valueNames[7]
|
|
|
|
}">${owner.login}</a>`,
|
2018-06-09 16:08:57 +02:00
|
|
|
'</li>',
|
|
|
|
].join('');
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
const indexTemplate = fs.readFileSync(templateHTML, 'utf8');
|
|
|
|
const $ = cheerio.load(indexTemplate);
|
|
|
|
const btn = valueNames.map(
|
2018-06-09 19:51:40 +02:00
|
|
|
v => `<button class="sort" data-sort="${v}">${v} </button>`,
|
2018-06-09 16:08:57 +02:00
|
|
|
);
|
|
|
|
$('#md').append(
|
|
|
|
[
|
2018-06-09 19:51:40 +02:00
|
|
|
`<div class="container">`,
|
|
|
|
`<div class="searchbar" ><input class="search" placeholder="Search" /></div>`,
|
|
|
|
`<div class="sortbtn" ><p>Sort by</p>${btn.join('')}</div>`,
|
|
|
|
// `<ul class="pagination"></ul>`,
|
|
|
|
`</div>`,
|
2018-06-09 16:08:57 +02:00
|
|
|
'<ul class="list">',
|
|
|
|
metaData.map(formatEntry).join(''),
|
|
|
|
'</ul>',
|
|
|
|
].join(''),
|
|
|
|
);
|
|
|
|
|
|
|
|
$('body').append(
|
|
|
|
'<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.js"></script>',
|
|
|
|
);
|
|
|
|
|
2018-06-09 19:51:40 +02:00
|
|
|
$('body').append(
|
|
|
|
[
|
|
|
|
'<script>',
|
|
|
|
`const userList = new List('md', {`,
|
|
|
|
` valueNames: ['name','description','homepage','star','updated','language','license','author'],`,
|
|
|
|
// ` page: 20,`,
|
|
|
|
// ` pagination: true,`,
|
|
|
|
`});`,
|
|
|
|
'</script>',
|
|
|
|
].join(''),
|
|
|
|
);
|
2018-06-09 16:08:57 +02:00
|
|
|
console.log('Writing table.html');
|
|
|
|
fs.writeFileSync(destination, $.html(), 'utf8');
|
|
|
|
console.log('DONE 👍');
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|