Moved client-side markdown rendering to this server

This commit is contained in:
2021-12-30 13:22:31 +00:00
parent da0c4bbd05
commit 2e2799f2d3
10 changed files with 166 additions and 6 deletions
+3
View File
@@ -1,5 +1,6 @@
const { Op } = require('sequelize');
const { articles, revisions } = require('../database/models');
const markdownIt = require('markdown-it')();
const route = async (req, res) => {
//get the existing record
@@ -20,6 +21,7 @@ const route = async (req, res) => {
title: record.title,
author: record.author,
body: record.body,
rendered: record.rendered,
originalIndex: record.index
});
@@ -28,6 +30,7 @@ const route = async (req, res) => {
title: req.body.title || record.title,
author: req.body.author || record.author,
body: req.body.body || record.body,
rendered: markdownIt.render(req.body.body) || record.rendered,
edits: record.edits + 1
}, {
where: {
+3 -1
View File
@@ -1,4 +1,5 @@
const { articles } = require('../database/models');
const markdownIt = require('markdown-it')();
const route = async (req, res) => {
//check for missing data
@@ -18,7 +19,8 @@ const route = async (req, res) => {
const [instance, created] = await articles.upsert({
title: req.body.title,
author: req.body.author,
body: req.body.body
body: req.body.body,
rendered: markdownIt.render(req.body.body),
});
if (!created) {
+2 -2
View File
@@ -7,7 +7,7 @@ const query = (ascending, metadataOnly) => async (req, res) => {
if (req.params.id && typeof(parseInt(req.params.id)) === 'number') {
const result = await articles.findOne({
attributes: [
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body'] : [])
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body', 'rendered'] : [])
],
where: {
index: {
@@ -24,7 +24,7 @@ const query = (ascending, metadataOnly) => async (req, res) => {
else {
const result = await articles.findAndCountAll({
attributes: [
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body'] : [])
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body', 'rendered'] : [])
],
order: [
['index', ascending ? 'ASC' : 'DESC']
+1
View File
@@ -20,6 +20,7 @@ const route = async (req, res) => {
title: record.title,
author: record.author,
body: record.body,
rendered: record.rendered,
originalIndex: record.index
});