added tag rendering events, added data utilty class
parent
3f4089a6d3
commit
d257d94a80
@ -0,0 +1,48 @@
|
||||
import Settings from './Settings';
|
||||
import Render from './Render';
|
||||
import StringUtils from '../../src/com/utils/StringUtils';
|
||||
import _ from 'lodash';
|
||||
const settings = new Settings();
|
||||
const render = new Render();
|
||||
const stringUtils = new StringUtils();
|
||||
|
||||
export default class Utils {
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
* Retrieves single page or pages
|
||||
* @parameter pages: payload of pages
|
||||
*/
|
||||
organizeTags(pages) {
|
||||
let tags = [];
|
||||
for (let index = 0; index < pages.length; index++) {
|
||||
const page = pages[index];
|
||||
let temp = [];
|
||||
temp = page.metadata.tags.split(',');
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
let label = temp[i].trim();
|
||||
if (!_.find(tags, { tag_name: label })) {
|
||||
tags.push({
|
||||
tag_name: label,
|
||||
slug: stringUtils.cleanString(label),
|
||||
count: 1
|
||||
});
|
||||
} else {
|
||||
_.find(tags, { tag_name: label }).count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
tags = _.orderBy(tags, ['tag_name'], ['asc']);
|
||||
|
||||
settings.saveTags(tags).then(() => {
|
||||
render
|
||||
.publishTags(pages)
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue