-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainView.js
62 lines (53 loc) · 1.93 KB
/
MainView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const Observable = require('FuseJS/Observable');
const StringHelper = require('./StringHelper');
const API = {
URL: 'https://public-api.wordpress.com/rest/v1.1/sites/superpikar.wordpress.com/',
fields: 'ID,title,author,date,url,excerpt,categories,attachments,tags,content'
}
const APIURL = `${API.URL}posts/slug:percobaan-format-text/?fields=${API.fields}`;
let post = Observable({
ID: '',
title: '',
content: '',
categories: '',
contentPlain: '',
contentHTML: '',
contentParagraphs: [],
contentParagraphsFormatted: [],
});
function loadPost() {
console.log('loadPost', APIURL);
fetch(APIURL)
.then(function(response) { return response.json(); })
.then(function(responseObject) {
responseObject.contentPlain = StringHelper.stripHTML(responseObject.content);
responseObject.contentHTML = StringHelper.renderToHtml(StringHelper.stripImage(responseObject.content));
responseObject.contentParagraphs = [];
responseObject.contentParagraphsFormatted = [];
const paragraphs = responseObject.contentPlain.split('\n');
paragraphs.forEach(function(val, key) {
responseObject.contentParagraphs.push({
content: val
});
});
console.log('------- paragraphs plain length', responseObject.contentParagraphs.length);
const paragraphs2 = responseObject.content.split('\n');
paragraphs2.forEach(function(val, key) {
var subParagraph = StringHelper.parseParagraph(val, key);
responseObject.contentParagraphsFormatted.push({
paragraphNumber: key,
paragraphContents: subParagraph.wordChunks,
paragraphAlignment: subParagraph.alignment
});
});
console.log('------- paragraphs auto length', responseObject.contentParagraphsFormatted.length);
post.value = responseObject
})
.catch(error => {
console.log(JSON.stringify(error));
})
}
loadPost();
module.exports = {
post: post,
};