Added document previews and fixed saving
This commit is contained in:
@@ -59,6 +59,7 @@
|
||||
"sequelize": "^3.21.0",
|
||||
"sequelize-cli": "^2.3.1",
|
||||
"sequelize-encrypted": "^0.1.0",
|
||||
"truncate-html": "0.0.6",
|
||||
"uuid": "^2.0.2",
|
||||
"validator": "^5.2.0"
|
||||
},
|
||||
|
||||
@@ -38,7 +38,8 @@ router.post('documents.create', auth(), async (ctx) => {
|
||||
ctx.assertPresent(title, 'title is required');
|
||||
ctx.assertPresent(text, 'text is required');
|
||||
|
||||
const team = await ctx.state.user.getTeam();
|
||||
const user = ctx.state.user;
|
||||
const team = await user.getTeam();
|
||||
const ownerAtlas = await Atlas.findOne({
|
||||
where: {
|
||||
id: atlas,
|
||||
@@ -51,6 +52,7 @@ router.post('documents.create', auth(), async (ctx) => {
|
||||
const document = await Document.create({
|
||||
atlasId: ownerAtlas.id,
|
||||
teamId: team.id,
|
||||
userId: user.id,
|
||||
title: title,
|
||||
text: text,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import marked from 'marked';
|
||||
import { truncateMarkdown } from './utils/truncate';
|
||||
|
||||
import Document from './models/Document';
|
||||
|
||||
@@ -45,7 +46,7 @@ export function presentAtlas(atlas, includeRecentDocuments=false) {
|
||||
|
||||
let recentDocuments = [];
|
||||
await Promise.all(documents.map(async (document) => {
|
||||
recentDocuments.push(await presentDocument(document));
|
||||
recentDocuments.push(await presentDocument(document, true));
|
||||
}))
|
||||
data.recentDocuments = recentDocuments;
|
||||
}
|
||||
@@ -60,6 +61,7 @@ export async function presentDocument(document, includeAtlas=false) {
|
||||
title: document.title,
|
||||
text: document.text,
|
||||
html: marked(document.text),
|
||||
preview: truncateMarkdown(document.text, 160),
|
||||
createdAt: document.createdAt,
|
||||
updatedAt: document.updatedAt,
|
||||
atlas: document.atlaId,
|
||||
|
||||
18
server/utils/truncate.js
Normal file
18
server/utils/truncate.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import truncate from 'truncate-html';
|
||||
import marked from 'marked';
|
||||
|
||||
truncate.defaultOptions = {
|
||||
stripTags: false,
|
||||
ellipsis: '...',
|
||||
decodeEntities: false,
|
||||
excludes: ['h1', 'pre',],
|
||||
};
|
||||
|
||||
const truncateMarkdown = (text, length) => {
|
||||
const html = marked(text);
|
||||
return truncate(html, length);
|
||||
};
|
||||
|
||||
export {
|
||||
truncateMarkdown
|
||||
};
|
||||
Reference in New Issue
Block a user