forked from projects/fipamo
inserted directory exists check when rendering md and html, completed index and page html rendering sequence chain
This commit is contained in:
parent
f6fc242d9c
commit
7243e5ec32
3 changed files with 129 additions and 111 deletions
|
@ -82,95 +82,97 @@ export default class Book {
|
||||||
'/' +
|
'/' +
|
||||||
moment(body.created).format('MM') +
|
moment(body.created).format('MM') +
|
||||||
'/'
|
'/'
|
||||||
);
|
).then(() => {
|
||||||
if (body.layout !== 'page') layout = body.layout;
|
if (body.layout !== 'page') layout = body.layout;
|
||||||
if (body.layout === null || body.layout === 'null') layout = 'page';
|
if (body.layout === null || body.layout === 'null') layout = 'page';
|
||||||
var pageWrite =
|
var pageWrite =
|
||||||
'---\n' +
|
'---\n' +
|
||||||
'id: ' +
|
'id: ' +
|
||||||
body.id +
|
body.id +
|
||||||
'\n' +
|
'\n' +
|
||||||
'uuid: ' +
|
'uuid: ' +
|
||||||
body.uuid +
|
body.uuid +
|
||||||
'\n' +
|
'\n' +
|
||||||
'title: ' +
|
'title: ' +
|
||||||
body.title +
|
body.title +
|
||||||
'\n' +
|
'\n' +
|
||||||
'feature: ' +
|
'feature: ' +
|
||||||
body.feature +
|
body.feature +
|
||||||
'\n' +
|
'\n' +
|
||||||
'path: ' +
|
'path: ' +
|
||||||
moment(body.created).format('YYYY') +
|
moment(body.created).format('YYYY') +
|
||||||
'/' +
|
'/' +
|
||||||
moment().format('MM') +
|
moment().format('MM') +
|
||||||
'\n' +
|
'\n' +
|
||||||
'layout: ' +
|
'layout: ' +
|
||||||
layout +
|
layout +
|
||||||
'\n' +
|
'\n' +
|
||||||
'tags: ' +
|
'tags: ' +
|
||||||
body.tags +
|
body.tags +
|
||||||
'\n' +
|
'\n' +
|
||||||
'author: ' +
|
'author: ' +
|
||||||
user.handle +
|
user.handle +
|
||||||
'\n' +
|
'\n' +
|
||||||
'created: ' +
|
'created: ' +
|
||||||
moment(body.created).format() +
|
moment(body.created).format() +
|
||||||
'\n' +
|
'\n' +
|
||||||
'updated: ' +
|
'updated: ' +
|
||||||
moment(Date.now()).format() +
|
moment(Date.now()).format() +
|
||||||
'\n' +
|
'\n' +
|
||||||
'deleted: ' +
|
'deleted: ' +
|
||||||
body.deleted +
|
body.deleted +
|
||||||
'\n' +
|
'\n' +
|
||||||
'menu: ' +
|
'menu: ' +
|
||||||
body.menu +
|
body.menu +
|
||||||
'\n' +
|
'\n' +
|
||||||
'featured: ' +
|
'featured: ' +
|
||||||
body.featured +
|
body.featured +
|
||||||
'\n' +
|
'\n' +
|
||||||
'published: ' +
|
'published: ' +
|
||||||
body.published +
|
body.published +
|
||||||
'\n' +
|
'\n' +
|
||||||
'slug: ' +
|
'slug: ' +
|
||||||
body.slug +
|
body.slug +
|
||||||
'\n' +
|
'\n' +
|
||||||
'---\n' +
|
'---\n' +
|
||||||
body.content;
|
body.content;
|
||||||
layout === 'index'
|
layout === 'index'
|
||||||
? (path = 'content/pages/' + body.slug + '.md')
|
? (path = 'content/pages/' + body.slug + '.md')
|
||||||
: (path =
|
: (path =
|
||||||
'content/pages/' +
|
'content/pages/' +
|
||||||
moment(body.created).format('YYYY') +
|
moment(body.created).format('YYYY') +
|
||||||
'/' +
|
'/' +
|
||||||
moment(body.created).format('MM') +
|
moment(body.created).format('MM') +
|
||||||
'/' +
|
'/' +
|
||||||
body.slug +
|
body.slug +
|
||||||
'.md');
|
'.md');
|
||||||
fs.writeFile(path, pageWrite, err => {
|
fs.writeFile(path, pageWrite, err => {
|
||||||
// throws an error, you could also catch it here
|
// throws an error, you could also catch it here
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
response = { type: DataEvent.PAGE_ERROR, message: err };
|
response = { type: DataEvent.PAGE_ERROR, message: err };
|
||||||
reject(response);
|
reject(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
// success case, the file was saved
|
// success case, the file was saved
|
||||||
if (task === DataEvent.API_PAGE_CREATE) {
|
if (task === DataEvent.API_PAGE_CREATE) {
|
||||||
// if new file, update settings index and page count
|
// if new file, update settings index and page count
|
||||||
response = {
|
response = {
|
||||||
type: DataEvent.PAGE_ADDED,
|
type: DataEvent.PAGE_ADDED,
|
||||||
message: 'New Page Created',
|
message: 'New Page Created',
|
||||||
id: body.uuid
|
id: body.uuid
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} else {
|
} else {
|
||||||
response = {
|
response = {
|
||||||
type: DataEvent.PAGE_UPDATED,
|
type: DataEvent.PAGE_UPDATED,
|
||||||
message: 'Page saved. Nice Work'
|
message: 'Page saved. Nice Work'
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DataEvent.API_PAGE_DELETE:
|
case DataEvent.API_PAGE_DELETE:
|
||||||
this.getPage(id)
|
this.getPage(id)
|
||||||
|
|
|
@ -7,6 +7,7 @@ const tags_list = require('../../site/tags.json');
|
||||||
const pug = require('pug');
|
const pug = require('pug');
|
||||||
const md = require('markdown-it')('commonmark');
|
const md = require('markdown-it')('commonmark');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
export default class Render {
|
export default class Render {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
@ -28,32 +29,47 @@ export default class Render {
|
||||||
let response = [];
|
let response = [];
|
||||||
for (let index = 0; index < pages.length; index++) {
|
for (let index = 0; index < pages.length; index++) {
|
||||||
const page = pages[index];
|
const page = pages[index];
|
||||||
|
let writeFile, template;
|
||||||
|
let path =
|
||||||
|
'public/' +
|
||||||
|
moment(page.metadata.created).format('YYYY') +
|
||||||
|
'/' +
|
||||||
|
moment(page.metadata.created).format('MM') +
|
||||||
|
'/';
|
||||||
if (page.metadata.layout === 'index') {
|
if (page.metadata.layout === 'index') {
|
||||||
let buffed = sanitize(page.content, {
|
template = 'content/themes/' + theme + '/index.pug';
|
||||||
allowedTags: ['del', 'a', 'iframe', 'img'],
|
writeFile = 'public/index.html';
|
||||||
allowedAttributes: {
|
} else {
|
||||||
a: ['href', 'name', 'target'],
|
writeFile = path + page.metadata.slug + '.html';
|
||||||
img: ['src'],
|
template = 'content/themes/' + theme + '/page.pug';
|
||||||
iframe: [
|
}
|
||||||
'height',
|
|
||||||
'width',
|
|
||||||
'src',
|
|
||||||
'frameborder',
|
|
||||||
'allow',
|
|
||||||
'allowfullscreen'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
buffed = new StringUtils().decodeHTML(buffed);
|
let buffed = sanitize(page.content, {
|
||||||
let html = md.render(buffed, { html: true, xhtmlOut: true });
|
allowedTags: ['del', 'a', 'iframe', 'img'],
|
||||||
let file = pug.renderFile('content/themes/' + theme + '/index.pug', {
|
allowedAttributes: {
|
||||||
title: page.metadata.title,
|
a: ['href', 'name', 'target'],
|
||||||
default_bg: page.metadata.feature,
|
img: ['src'],
|
||||||
content_index: html
|
iframe: [
|
||||||
});
|
'height',
|
||||||
|
'width',
|
||||||
|
'src',
|
||||||
|
'frameborder',
|
||||||
|
'allow',
|
||||||
|
'allowfullscreen'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
fs.writeFile('public/index.html', file, err => {
|
buffed = new StringUtils().decodeHTML(buffed);
|
||||||
|
let html = md.render(buffed, { html: true, xhtmlOut: true });
|
||||||
|
let file = pug.renderFile(template, {
|
||||||
|
title: page.metadata.title,
|
||||||
|
default_bg: page.metadata.feature,
|
||||||
|
content: html
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.ensureDir(path).then(() => {
|
||||||
|
fs.writeFile(writeFile, file, err => {
|
||||||
// throws an error, you could also catch it here
|
// throws an error, you could also catch it here
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -68,7 +84,7 @@ export default class Render {
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ router.get('/', function (req, res) {
|
||||||
.then(obj => {
|
.then(obj => {
|
||||||
settings = obj;
|
settings = obj;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(() => {
|
||||||
//console.error(err);
|
//console.error(err);
|
||||||
});
|
});
|
||||||
loadThemes().then(themes => {
|
loadThemes().then(themes => {
|
||||||
|
|
Loading…
Reference in a new issue