basic markdown file rending working. fuck. yes.

This commit is contained in:
Ro 2019-11-24 16:11:12 -08:00
parent 849c5e2ac0
commit 74225b627e
7 changed files with 146 additions and 47 deletions

View file

@ -51,7 +51,60 @@ router.get('/', (req, res) => {
Update Page Update Page
*/ */
router.post('/write', feature_upload, (req, res) => { router.post('/write', feature_upload, (req, res) => {
console.log('FILEZ BRAH', req.files); var feature = '';
if (req.files.lengh > 0) {
} else {
var url = req.body.feature_image;
feature = url.substring(21, url.length);
}
var pageWrite =
'---\n' +
'id: ' +
req.body.page_id +
'\n' +
'uuid: ' +
req.body.page_uuid +
'\n' +
'title: ' +
req.body.title +
'\n' +
'feature: ' +
feature +
'\n' +
'layout: ' +
'page' +
'\n' +
'tags: ' +
req.body.tags +
'\n' +
'author: ' +
req.session.user.handle +
'\n' +
'created: ' +
req.body.created +
'\n' +
'updated: ' +
moment(Date.now()).format() +
'\n' +
'featured: ' +
req.body.featureStatus +
'\n' +
'published: ' +
req.body.publishedStatus +
'\n' +
'slug: ' +
req.body.slug +
'\n' +
'---\n\n' +
req.body.content;
fs.writeFile('content/pages/test.md', pageWrite, err => {
// throws an error, you could also catch it here
if (err) res.json({ type: DataEvent.PAGE_ERROR, message: err });
// success case, the file was saved
res.json({ type: DataEvent.PAGE_UPDATED, message: 'Page Has been saved' });
});
}); });
module.exports = router; module.exports = router;

View file

@ -57,12 +57,14 @@ router.get('/edit/:id', function(req, res) {
let pretty = hljs.highlight('markdown', page.content).value; let pretty = hljs.highlight('markdown', page.content).value;
res.render('page-edit', { res.render('page-edit', {
id: page.metadata.id, id: page.metadata.id,
uuid: page.metadata.uuid,
title: 'Edit Page', title: 'Edit Page',
user_status: true, user_status: true,
welcome: 'Edit Page', welcome: 'Edit Page',
mode: 'admin', mode: 'admin',
page: page.metadata, page: page.metadata,
date: moment(page.metadata.created).format('YYYY MMM DD'), date: moment(page.metadata.created).format('YYYY MMM DD'),
rawDate: page.metadata.created,
colored: pretty, colored: pretty,
feature: page.metadata.feature, feature: page.metadata.feature,
status: [ status: [

View file

@ -18,7 +18,7 @@ block main-content
-post_status = status -post_status = status
form#test-form form#test-form
#post-edit-index(data-index=id) #post-edit-index(data-index=id data-uuid=uuid)
#post-edit-index-wrapper #post-edit-index-wrapper
//h2 EDIT //h2 EDIT
=post_title =post_title
@ -35,7 +35,7 @@ block main-content
svg#new-feature-upload(viewBox="0 0 20 20" class="icons") svg#new-feature-upload(viewBox="0 0 20 20" class="icons")
use(xlink:href='/assets/images/global/sprite.svg#entypo-image-inverted') use(xlink:href='/assets/images/global/sprite.svg#entypo-image-inverted')
#featured-image-drop #featured-image-drop
img(src=post_feature) img#featured-image(src=post_feature)
#post-header.columns #post-header.columns
#post-title.column #post-title.column
textarea(id="post_title" type='text', name='post_title' class='post-edit', placeholder='title', required, autofocus) textarea(id="post_title" type='text', name='post_title' class='post-edit', placeholder='title', required, autofocus)
@ -43,7 +43,7 @@ block main-content
#calendar-icon #calendar-icon
svg(viewBox="0 0 20 20" class="icons") svg(viewBox="0 0 20 20" class="icons")
use(xlink:href='/assets/images/global/sprite.svg#entypo-calendar') use(xlink:href='/assets/images/global/sprite.svg#entypo-calendar')
input(id="post-date" type="text" value=post_date) input(id="post-date" type="text" value=post_date data-raw=rawDate)
#post-options #post-options
button#option-page.option-inactive.post-option-btn(data-active= status[0]) button#option-page.option-inactive.post-option-btn(data-active= status[0])
svg#option-page-icon(viewBox="0 0 20 20" class="icons") svg#option-page-icon(viewBox="0 0 20 20" class="icons")

View file

@ -1,6 +1,7 @@
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../utils/DataUtils'; import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../utils/DataUtils';
import StringUtils from '../utils/StringUtils'; import StringUtils from '../utils/StringUtils';
import * as DataEvent from '../events/DataEvent'; import * as DataEvent from '../events/DataEvent';
import { isMaster } from 'cluster';
var uuidv4 = require('uuid/v4'); var uuidv4 = require('uuid/v4');
export default class PostActions { export default class PostActions {
//-------------------------- //--------------------------
@ -12,6 +13,62 @@ export default class PostActions {
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
collectInfo(image) {
return new Promise((resolve, reject) => {
let pageInfo = new FormData();
let txt = document.createElement('textarea');
txt.innerHTML = document.getElementById('edit-post-text').innerHTML;
let html = txt.value;
html = html.replace(/<\/?span[^>]*>/g, ''); //removes highightjs styling
html = html.replace(/<\/?br[^>]*>/g, '\n'); //convert back to encoded line break for storage
pageInfo.append(
'page_id',
document.getElementById('post-edit-index').getAttribute('data-index')
);
pageInfo.append(
'page_uuid',
document.getElementById('post-edit-index').getAttribute('data-uuid')
);
pageInfo.append('content', html);
pageInfo.append('title', document.getElementById('post_title').value);
pageInfo.append(
'created',
document.getElementById('post-date').getAttribute('data-raw')
);
pageInfo.append(
'slug',
new StringUtils().cleanString(document.getElementById('post_title').value)
);
pageInfo.append('tags', document.getElementById('post_tags').value);
pageInfo.append(
'pageStatus',
document.getElementById('option-page').getAttribute('data-active')
);
pageInfo.append(
'featureStatus',
document.getElementById('option-feature').getAttribute('data-active')
);
pageInfo.append(
'publishedStatus',
document.getElementById('option-published').getAttribute('data-active')
);
if (image != null || image != undefined) {
if (image.type.match('image.*')) {
pageInfo.append('feature_image', image, image.name);
} else {
reject('Not an image file');
}
} else {
//check to see if image exists
var imageURL = document.getElementById('featured-image').src;
imageURL != null || imageURL != undefined
? pageInfo.append('feature_image', imageURL)
: pageInfo.append('feature_image', null);
}
resolve(pageInfo);
});
}
update(id, data, files, lastKey) { update(id, data, files, lastKey) {
let self = this; let self = this;
let freshData; let freshData;

View file

@ -1,10 +1,10 @@
//TOOLS //TOOLS
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_FORM } from '../../../src/com/utils/DataUtils'; import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_FORM } from '../utils/DataUtils';
import * as DataEvent from '../../../src/com/events/DataEvent'; import * as DataEvent from '../events/DataEvent';
import PostActions from '../actions/PostActions'; import PageActions from '../actions/PageActions';
import * as EditorEvent from '../../../src/com/events/EditorEvent'; import * as EditorEvent from '../events/EditorEvent';
import TinyDatePicker from 'tiny-date-picker'; import TinyDatePicker from 'tiny-date-picker';
import TextEditor from '../../../src/com/ui/TextEditor'; import TextEditor from '../ui/TextEditor';
const data = new DataUtils(); const data = new DataUtils();
export default class PostEditor { export default class PostEditor {
//TODO - FIX POST FEATURE URLS IN DB //TODO - FIX POST FEATURE URLS IN DB
@ -117,7 +117,7 @@ export default class PostEditor {
let self = this; let self = this;
switch (e) { switch (e) {
case EditorEvent.EDITOR_SAVE: case EditorEvent.EDITOR_SAVE:
new PostActions() new PageActions()
.update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY) .update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY)
.then(response => { .then(response => {
setTimeout(() => { setTimeout(() => {
@ -131,40 +131,28 @@ export default class PostEditor {
}); });
break; break;
case EditorEvent.EDITOR_UPDATE: case EditorEvent.EDITOR_UPDATE:
var pageData = new FormData(); new PageActions()
pageData.append('name', 'HAMMOCK LANSING'); .collectInfo(document.getElementById('featured-image-upload').files[0])
var image = document.getElementById('featured-image-upload').files[0]; .then(page => {
if (image != null || image != undefined) { data.request(
pageData.append('feature_image', image, image.name); '/api/v1/page/write',
} DataEvent.API_PAGE_WRITE,
REQUEST_TYPE_POST,
data.request( CONTENT_TYPE_FORM,
'/api/v1/page/write', page
DataEvent.API_PAGE_WRITE, )
REQUEST_TYPE_POST, .then(response => {
CONTENT_TYPE_FORM, let r = JSON.parse(response.request['response']);
pageData console.log('RESPONSE', r.message);
) })
.then(r => { .catch(err => {
console.log('RESPONSE', r); console.log('ERROR', err);
}) });
.catch(err => {
console.log('ERROR', err);
}); });
/**
new PostActions()
.update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY)
.then(() => {
this.editor.notify(DataEvent.POST_UPDATED, this.postID);
})
.catch(() => {
//console.log("ERRORZ", err)
});
*/
break; break;
case EditorEvent.EDITOR_DELETE: case EditorEvent.EDITOR_DELETE:
if (confirm("Aye! You know you're deleting this post, right?")) { if (confirm("Aye! You know you're deleting this post, right?")) {
new PostActions() new PageActions()
.deletePost(this.postID, this.post) .deletePost(this.postID, this.post)
.then(() => { .then(() => {
setTimeout(() => { setTimeout(() => {

View file

@ -1,4 +1,4 @@
import PostEditor from './PostEditor'; import PageEditor from './PageEditor';
export default class PostIndex { export default class PostIndex {
//-------------------------- //--------------------------
// constructor // constructor
@ -17,7 +17,7 @@ export default class PostIndex {
switch (page) { switch (page) {
case 'edit': case 'edit':
case 'add': case 'add':
this.currentPage = new PostEditor(); this.currentPage = new PageEditor();
break; break;
default: default:
//just chill //just chill

View file

@ -5,11 +5,10 @@ export const IMG_REQUEST_LAME = 'imgRequestLame';
export const SETTINGS_LOADED = 'settingsLoaded'; export const SETTINGS_LOADED = 'settingsLoaded';
export const POST_IMAGE_ADDED = 'postImageAdded'; export const POST_IMAGE_ADDED = 'postImageAdded';
export const FEATURE_IMAGE_ADDED = 'featureImageAdded'; export const FEATURE_IMAGE_ADDED = 'featureImageAdded';
export const POST_ERROR = 'postError'; export const PAGE_ERROR = 'postError';
export const POST_ADDED = 'postAdded'; export const PAGE_ADDED = 'postAdded';
export const POST_UPDATED = 'postUpdated'; export const PAGE_UPDATED = 'postUpdated';
export const POST_DELETED = 'postImageAdded'; export const PAGE_DELETED = 'postImageAdded';
export const POSTS_SYNCED = 'postsSynced';
export const SETTINGS_UPDATED = 'settingsUpdated'; export const SETTINGS_UPDATED = 'settingsUpdated';
export const AVATAR_UPLOADED = 'avatarUploaded'; export const AVATAR_UPLOADED = 'avatarUploaded';
export const SITE_BACKGROUND_UPLOADED = 'siteBackgroundUploaded'; export const SITE_BACKGROUND_UPLOADED = 'siteBackgroundUploaded';