Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit fe6dc61

Browse files
committed
to add new draft syntax now
1 parent aa20b07 commit fe6dc61

File tree

4 files changed

+150
-257
lines changed

4 files changed

+150
-257
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "npm-run-all --parallel clean:dev build:dev webpack:dev",
1010
"upload": "node scripts/upload.js",
1111
"push": "node scripts/push.js",
12-
"build:dev": "node scripts/deu.js",
12+
"build:dev": "node scripts/dev.js",
1313
"build:dist": "node scripts/generate.js",
1414
"webpack:dev": "webpack --env=dev --progress --colors --watch",
1515
"webpack:dist": "webpack --env=prod --progress --colors",

scripts/deu.js

-144
This file was deleted.

scripts/dev.js

+60-52
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function generateTemplates(){
3434
let flatPosts = posts.reduce((posts_prev,posts_next)=>posts_prev.concat(posts_next));
3535
let pagination = {next:null,prev:null};
3636

37-
// index pages
37+
// index pages and pagination
3838
posts.forEach((post_arr,cur_page)=>{
3939
pagination = Object.assign(pagination,
4040
{
@@ -57,50 +57,20 @@ function generateTemplates(){
5757
utils.generatePostTemplate(post,labels,'dev');
5858
});
5959

60-
console.log(chalk.bold.green(`Templates generated. \nAvailable on:\n http://localhost:${PORT}`));
61-
}
62-
60+
// other pages
61+
utils.generatePageTemplate('dev');
6362

64-
// fetch github data
63+
// category pages
64+
utils.generateCategoryTemplates2(labels,'dev')
6565

66-
function fetchAndStoreData(){
67-
blog.fetchBlogPosts()
68-
.then(_posts=>{
69-
70-
posts.push(_posts);
71-
72-
if(!blog.settings.posts.last_reached){
73-
fetchAndStoreData();
74-
}
75-
else {
76-
spinner.stop();
77-
posts[0].unshift(...listOfFiles)
78-
startDevMode();
79-
}
80-
})
81-
.catch(function(err){
82-
spinner.stop();
83-
console.log(chalk.bold.red('Could not fetch github data for some reason\nUsing offline data.'));
84-
posts.push(listOfFiles)
85-
startDevMode();
86-
});
66+
console.log(chalk.bold.green(`Templates generated. \nAvailable on:\n http://localhost:${PORT}`));
8767
}
8868

8969
function startDevMode(){
9070

9171
mkdirp.sync(path.join(ROOT_DIR,'dev','category'));
9272
mkdirp.sync(path.join(ROOT_DIR,'dev','posts'));
93-
// Promise.all the creation of category pages
94-
// then create index and other pages
95-
// There is mixed use of sync and async functions
96-
// need to fix that
97-
Promise.all(utils.generateCategoryTemplates(labels,'dev'))
98-
.then(()=>{
99-
// index and post pages
100-
generateTemplates();
101-
// other pages
102-
utils.generatePageTemplate('dev');
103-
});
73+
generateTemplates();
10474

10575
// watch for changes in the theme directory and regenerate on change
10676
chokidar.watch(THEME_DIR, {ignored: /(^|[\/\\])\../}).on('all', (event, path) => {
@@ -110,27 +80,65 @@ function startDevMode(){
11080
});
11181
}
11282

113-
// start the dev thing
114-
spinner.start();
115-
blog.fetchAllLabels()
83+
function getAllPosts(){
84+
let posts = [];
85+
return new Promise((resolve,reject)=>{
86+
(function callFetchBlogPosts(){
87+
blog.fetchBlogPosts()
88+
.then(_posts=>{
89+
if(blog.settings.posts.last_reached){
90+
resolve(posts);
91+
}
92+
else{
93+
callFetchBlogPosts();
94+
}
95+
posts.push(_posts);
96+
})
97+
.catch(function(err){
98+
console.log(chalk.bold.red('Could not fetch github data for some reason\nUsing offline data.'));
99+
resolve(posts);
100+
});
101+
})()
102+
});
103+
}
104+
105+
function getAllLabels(){
106+
return new Promise((resolve,reject)=>{
107+
blog.fetchAllLabels()
116108
.then(_labels=>{
117-
labels = _labels;
118-
let fileContents = utils.getOfflineFileContents();
119-
Promise.all(fileContents).then((offlineFileContents)=>{
120-
listOfFiles = offlineFileContents;
121-
fetchAndStoreData();
122-
});
109+
resolve(_labels);
123110
})
124111
.catch(err=>{
125-
let fileContents = utils.getOfflineFileContents();
126-
Promise.all(fileContents).then((offlineFileContents)=>{
127-
listOfFiles = offlineFileContents;
128-
fetchAndStoreData();
129-
});
130-
console.log(chalk.bold.red('Could not fetch github data due to network issue'));
112+
console.log(chalk.bold.red('Could not fetch github label data due to network issue'));
113+
resolve(labels);
131114
});
115+
});
116+
}
132117

133118

119+
function fetchAndStoreData(){
120+
Promise.all([getAllPosts(), getAllLabels(),utils.getOfflineFileContents()])
121+
.then(vals=>{
122+
spinner.stop();
123+
posts = vals[0];
124+
labels = vals[1];
125+
listOfFiles = vals[2];
126+
posts[0].unshift(...listOfFiles)
127+
startDevMode();
128+
})
129+
.catch(err=>{
130+
spinner.stop();
131+
utils.getOfflineFileContents()
132+
.then(files=>{
133+
posts.push(files)
134+
startDevMode();
135+
})
136+
})
137+
}
138+
139+
spinner.start();
140+
fetchAndStoreData();
141+
134142
// start the dev server silently
135143
server.start({
136144
port: PORT,

0 commit comments

Comments
 (0)