|
|
|
@ -5,6 +5,7 @@ import _ from 'lodash';
|
|
|
|
|
const settings = new Settings();
|
|
|
|
|
const render = new Render();
|
|
|
|
|
const stringUtils = new StringUtils();
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
|
|
export default class Utils {
|
|
|
|
|
constructor() {}
|
|
|
|
@ -45,4 +46,50 @@ export default class Utils {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
organizeArchive(pages) {
|
|
|
|
|
let years = [];
|
|
|
|
|
let archive = [];
|
|
|
|
|
for (let index = 0; index < pages.length; index++) {
|
|
|
|
|
let page = pages[index].metadata;
|
|
|
|
|
let year = moment(page.created).format('YYYY');
|
|
|
|
|
if (!_.find(years, { year: year })) {
|
|
|
|
|
years.push({ year: year, count: 1 });
|
|
|
|
|
} else {
|
|
|
|
|
_.find(years, { year: year }).count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
years.sort((a, b) => parseFloat(b.year) - parseFloat(a.year));
|
|
|
|
|
for (let index = 0; index < years.length; index++) {
|
|
|
|
|
let item = years[index];
|
|
|
|
|
let sorted = [];
|
|
|
|
|
let filtered = _.filter(pages, page => {
|
|
|
|
|
return moment(page.metadata.created).format('YYYY') === item.year;
|
|
|
|
|
});
|
|
|
|
|
for (let index = 0; index < filtered.length; index++) {
|
|
|
|
|
let obj = filtered[index].metadata;
|
|
|
|
|
let month = moment(obj.created).format('MM');
|
|
|
|
|
if (!_.find(sorted, { month: month })) {
|
|
|
|
|
let sortedPages = _.filter(pages, page => {
|
|
|
|
|
return (
|
|
|
|
|
moment(page.metadata.created).format('YYYY') === item.year &&
|
|
|
|
|
moment(page.metadata.created).format('MM') === month
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sorted.push({
|
|
|
|
|
month: month,
|
|
|
|
|
full_month: moment(obj.created).format('MMMM'),
|
|
|
|
|
count: 1,
|
|
|
|
|
pages: sortedPages
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
_.find(sorted, { month: month }).count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
archive.push({ year: item.year, year_data: sorted });
|
|
|
|
|
}
|
|
|
|
|
render.publishArchive(archive);
|
|
|
|
|
//console.log('ARCHIVE', archive[0].meta[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|