feat: editor - existing content
This commit is contained in:
@@ -7,8 +7,28 @@ const pageHelper = require('../helpers/page')
|
||||
/**
|
||||
* Create/Edit document
|
||||
*/
|
||||
router.get(['/e', '/e/*'], (req, res, next) => {
|
||||
res.render('editor')
|
||||
router.get(['/e', '/e/*'], async (req, res, next) => {
|
||||
const pageArgs = pageHelper.parsePath(req.path)
|
||||
let page = await WIKI.models.pages.getPageFromDb({
|
||||
path: pageArgs.path,
|
||||
locale: pageArgs.locale,
|
||||
userId: req.user.id,
|
||||
isPrivate: false
|
||||
})
|
||||
if (page) {
|
||||
page.mode = 'update'
|
||||
page.isPublished = (page.isPublished === true || page.isPublished === 1) ? 'true' : 'false'
|
||||
page.content = Buffer.from(page.content).toString('base64')
|
||||
} else {
|
||||
page = {
|
||||
path: pageArgs.path,
|
||||
localeCode: pageArgs.locale,
|
||||
editorKey: null,
|
||||
mode: 'create',
|
||||
content: null
|
||||
}
|
||||
}
|
||||
res.render('editor', { page })
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -41,7 +61,7 @@ router.get('/*', async (req, res, next) => {
|
||||
} else if (pageArgs.path === 'home') {
|
||||
res.render('welcome')
|
||||
} else {
|
||||
res.render('new')
|
||||
res.render('new', { pagePath: req.path })
|
||||
}
|
||||
})
|
||||
|
||||
|
@@ -21,8 +21,11 @@ module.exports = {
|
||||
|
||||
// Extract Info
|
||||
let pathParts = _.filter(_.split(rawPath, '/'), p => !_.isEmpty(p))
|
||||
if (pathParts[0].length === 1) {
|
||||
pathParts.shift()
|
||||
}
|
||||
if (pathParts[0].length === 2) {
|
||||
pathObj = pathParts[0]
|
||||
pathObj.locale = pathParts[0]
|
||||
pathParts.shift()
|
||||
}
|
||||
pathObj.path = _.join(pathParts, '/')
|
||||
|
@@ -187,7 +187,9 @@ module.exports = class Page extends Model {
|
||||
let page = await WIKI.models.pages.getPageFromCache(opts)
|
||||
if (!page) {
|
||||
page = await WIKI.models.pages.getPageFromDb(opts)
|
||||
await WIKI.models.pages.savePageToCache(page)
|
||||
if (page) {
|
||||
await WIKI.models.pages.savePageToCache(page)
|
||||
}
|
||||
}
|
||||
return page
|
||||
}
|
||||
|
@@ -3,4 +3,14 @@ extends master.pug
|
||||
block body
|
||||
#root
|
||||
v-app
|
||||
editor
|
||||
editor(
|
||||
locale=page.localeCode
|
||||
path=page.path
|
||||
title=page.title
|
||||
description=page.description
|
||||
tags=page.tags
|
||||
:is-published=page.isPublished
|
||||
init-mode=page.mode
|
||||
init-editor=page.editorKey
|
||||
init-content=page.content
|
||||
)
|
||||
|
@@ -8,7 +8,7 @@ block body
|
||||
img.animated.fadeIn(src='/svg/henry-thinking.svg', alt='Henry')
|
||||
.headline= t('newpage.title')
|
||||
.subheading.mt-3= t('newpage.subtitle')
|
||||
v-btn.mt-5(href='/e/home', large)
|
||||
v-btn.mt-5(href='/e' + pagePath, large)
|
||||
v-icon(left) add
|
||||
span= t('newpage.create')
|
||||
v-btn.mt-2(color='blue lighten-4', href='javascript:window.history.go(-1);', large, outline)
|
||||
|
@@ -13,7 +13,7 @@ block body
|
||||
created-at=page.createdAt
|
||||
updated-at=page.updatedAt
|
||||
author-name=page.authorName
|
||||
author-id=page.authorId
|
||||
:author-id=page.authorId
|
||||
is-published=page.isPublished
|
||||
)
|
||||
template(slot='contents')!= page.render
|
||||
|
Reference in New Issue
Block a user