Skip to content

Commit

Permalink
#99 fixed to store html instead json in db
Browse files Browse the repository at this point in the history
  • Loading branch information
kotte-sanya committed Sep 29, 2020
1 parent 50a869f commit 8359287
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 60 deletions.
6 changes: 3 additions & 3 deletions infrastructure/src/handlers/items/createBlog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const slugify = require('slugify');
const dayjs = require('dayjs');
const customParseFormat = require('dayjs/plugin/customParseFormat');
// const sanitizeHtml = require('sanitize-html');
const sanitizeHtml = require('sanitize-html');

dayjs.extend(customParseFormat);

Expand Down Expand Up @@ -60,7 +60,7 @@ module.exports = (app) => {
};

function insertItem(dbClient, blogId, title, source, author, publishDate, picture, tags) {
let content = '';
const content = sanitizeHtml(source, api.sanitizeConfigure());
const slug = slugify(title, { lower: true, strict: true });

const blog = {
Expand All @@ -79,7 +79,7 @@ function insertItem(dbClient, blogId, title, source, author, publishDate, pictur
},
data: {
content,
source,
// source,
},
comments: {
count: 0,
Expand Down
6 changes: 3 additions & 3 deletions infrastructure/src/handlers/items/updateBlog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// const sanitizeHtml = require('sanitize-html');
const sanitizeHtml = require('sanitize-html');
const mongo = require('../../utils/mongo.js');
const api = require('../../utils/api.js');
const auth = require('../../utils/authenticate');
Expand Down Expand Up @@ -42,9 +42,9 @@ module.exports = (app) => {
};

function prepareUpdateQuery(source, title, picture, tags) {
let content = '';
const content = sanitizeHtml(source, api.sanitizeConfigure());
const setters = {};
setters['data.source'] = source;
// setters['data.source'] = source;
setters['data.content'] = content;
setters['info.caption'] = title;
setters['info.picture'] = picture;
Expand Down
57 changes: 5 additions & 52 deletions spa/src/views/item/Blog.vue
Original file line number Diff line number Diff line change
@@ -1,72 +1,26 @@
<template>
<div class="pt-3 w-75 m-auto pb-5">
<h1>{{title}}</h1>
<editor-content class="editor__content" :editor="editor" />
<div v-html="blogHtml"></div>
</div>
</template>

<script>
import { Editor, EditorContent } from 'tiptap';
import {
Blockquote,
CodeBlock,
HardBreak,
Heading,
HorizontalRule,
OrderedList,
BulletList,
ListItem,
TodoItem,
TodoList,
Bold,
Code,
Italic,
Link,
Strike,
Underline,
History,
} from 'tiptap-extensions';
import Image from '@/utils/editorImage';
export default {
name: 'blog',
components: {
EditorContent,
},
props: {
slug: String,
},
data() {
return {
editor: new Editor({
extensions: [
new Blockquote(),
new BulletList(),
new CodeBlock(),
new HardBreak(),
new Heading({ levels: [1, 2, 3] }),
new HorizontalRule(),
new ListItem(),
new OrderedList(),
new TodoItem(),
new TodoList(),
new Link(),
new Bold(),
new Code(),
new Italic(),
new Strike(),
new Underline(),
new History(),
new Image(),
],
editable: false,
}),
blogHtml: '',
};
},
watch: {
blog() {
this.setContent(this.blog.data.source);
this.setContent(this.blog.data.content);
},
},
computed: {
Expand All @@ -85,9 +39,8 @@ export default {
this.$store.dispatch('FETCH_BLOG', { slug: this.slug });
},
methods: {
setContent(json) {
this.editor.setContent(json, true);
this.editor.focus();
setContent(html) {
this.blogHtml = html;
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions spa/src/views/item/WriteBlog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ export default {
this.title = this.blog.info.caption;
this.picture = this.blog.info.picture;
this.tags = this.blog.info.tags;
this.setContent(this.blog.data.source);
this.setContent(this.blog.data.content);
},
},
methods: {
async saveBlog() {
const editorData = this.json;
const editorData = this.html;
const body = {
title: this.title,
Expand Down

0 comments on commit 8359287

Please sign in to comment.