feat: save editor render

pull/6775/head
NGPixel 2 years ago
parent a6041b4ba5
commit fc820eb1b6
No known key found for this signature in database
GPG Key ID: B755FB6870B30F63

@ -85,6 +85,7 @@ extend type Mutation {
publishEndDate: Date publishEndDate: Date
publishStartDate: Date publishStartDate: Date
relations: [PageRelationInput!] relations: [PageRelationInput!]
render: String
scriptCss: String scriptCss: String
scriptJsLoad: String scriptJsLoad: String
scriptJsUnload: String scriptJsUnload: String
@ -236,6 +237,7 @@ type PageVersion {
path: String path: String
publishEndDate: Date publishEndDate: Date
publishStartDate: Date publishStartDate: Date
render: String
tags: [String] tags: [String]
title: String title: String
versionId: Int versionId: Int
@ -342,6 +344,7 @@ input PageUpdateInput {
publishStartDate: Date publishStartDate: Date
publishState: PagePublishState publishState: PagePublishState
relations: [PageRelationInput!] relations: [PageRelationInput!]
render: String
scriptJsLoad: String scriptJsLoad: String
scriptJsUnload: String scriptJsUnload: String
scriptCss: String scriptCss: String

@ -46,6 +46,7 @@ module.exports = class Page extends Model {
publishEndDate: {type: 'string'}, publishEndDate: {type: 'string'},
content: {type: 'string'}, content: {type: 'string'},
contentType: {type: 'string'}, contentType: {type: 'string'},
render: {type: 'string'},
siteId: {type: 'string'}, siteId: {type: 'string'},
createdAt: {type: 'string'}, createdAt: {type: 'string'},
updatedAt: {type: 'string'} updatedAt: {type: 'string'}
@ -321,6 +322,7 @@ module.exports = class Page extends Model {
publishEndDate: opts.publishEndDate?.toISO(), publishEndDate: opts.publishEndDate?.toISO(),
publishStartDate: opts.publishStartDate?.toISO(), publishStartDate: opts.publishStartDate?.toISO(),
relations: opts.relations ?? [], relations: opts.relations ?? [],
render: opts.render ?? '',
siteId: opts.siteId, siteId: opts.siteId,
title: opts.title, title: opts.title,
toc: '[]', toc: '[]',
@ -445,6 +447,9 @@ module.exports = class Page extends Model {
if ('content' in opts.patch) { if ('content' in opts.patch) {
patch.content = opts.patch.content patch.content = opts.patch.content
if ('render' in opts.patch) {
patch.render = opts.patch.render
}
historyData.affectedFields.push('content') historyData.affectedFields.push('content')
} }

@ -18,7 +18,7 @@ module.exports = async ({ payload }) => {
const pipeline = await WIKI.db.renderers.getRenderingPipeline(page.contentType) const pipeline = await WIKI.db.renderers.getRenderingPipeline(page.contentType)
let output = page.content let output = page.render
if (_.isEmpty(page.content)) { if (_.isEmpty(page.content)) {
WIKI.logger.warn(`Failed to render page ID ${payload.id} because content was empty: [ FAILED ]`) WIKI.logger.warn(`Failed to render page ID ${payload.id} because content was empty: [ FAILED ]`)

@ -228,7 +228,7 @@
.editor-markdown-preview-content.contents(ref='editorPreviewContainer') .editor-markdown-preview-content.contents(ref='editorPreviewContainer')
div( div(
ref='editorPreview' ref='editorPreview'
v-html='state.previewHTML' v-html='pageStore.render'
) )
</template> </template>
@ -286,7 +286,6 @@ const cmRef = ref(null)
const state = reactive({ const state = reactive({
previewShown: true, previewShown: true,
previewHTML: '',
previewScrollSync: true previewScrollSync: true
}) })
@ -403,10 +402,12 @@ function toggleMarkup ({ start, end }) {
cm.value.doc.replaceSelections(cm.value.doc.getSelections().map(s => start + s + end)) cm.value.doc.replaceSelections(cm.value.doc.getSelections().map(s => start + s + end))
} }
const onCmInput = debounce(processContent, 600) const onCmInput = debounce(processContent, 500)
function processContent (newContent) { function processContent (newContent) {
state.previewHTML = md.render(newContent) pageStore.$patch({
render: md.render(newContent)
})
} }
// MOUNTED // MOUNTED

@ -114,8 +114,10 @@ import { onBeforeUnmount, onMounted, reactive, shallowRef } from 'vue'
import { useMeta, useQuasar, setCssVar } from 'quasar' import { useMeta, useQuasar, setCssVar } from 'quasar'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { DateTime } from 'luxon'
import { useEditorStore } from 'src/stores/editor' import { useEditorStore } from 'src/stores/editor'
import { usePageStore } from 'src/stores/page'
import { useSiteStore } from 'src/stores/site' import { useSiteStore } from 'src/stores/site'
// QUASAR // QUASAR
@ -125,6 +127,7 @@ const $q = useQuasar()
// STORES // STORES
const editorStore = useEditorStore() const editorStore = useEditorStore()
const pageStore = usePageStore()
const siteStore = useSiteStore() const siteStore = useSiteStore()
// I18N // I18N
@ -678,7 +681,7 @@ function init () {
// -> Initialize TipTap // -> Initialize TipTap
editor = useEditor({ editor = useEditor({
content: '<p>Im running Tiptap with Vue.js. 🎉</p>', // editorStore.content, content: pageStore.content && pageStore.content.startsWith('{') ? JSON.parse(pageStore.content) : `<p>${pageStore.content}</p>`,
extensions: [ extensions: [
StarterKit.configure({ StarterKit.configure({
codeBlock: false, codeBlock: false,
@ -716,8 +719,14 @@ function init () {
TextStyle, TextStyle,
Typography Typography
], ],
onUpdate: () => { onUpdate: ({ editor }) => {
// this.$store.set('page/render', editor.getHTML()) editorStore.$patch({
lastChangeTimestamp: DateTime.utc()
})
pageStore.$patch({
content: JSON.stringify(editor.getJSON()),
render: editor.getHTML()
})
} }
}) })
} }

@ -126,6 +126,7 @@ const gqlMutations = {
$publishEndDate: Date $publishEndDate: Date
$publishStartDate: Date $publishStartDate: Date
$relations: [PageRelationInput!] $relations: [PageRelationInput!]
$render: String
$scriptCss: String $scriptCss: String
$scriptJsLoad: String $scriptJsLoad: String
$scriptJsUnload: String $scriptJsUnload: String
@ -152,6 +153,7 @@ const gqlMutations = {
publishEndDate: $publishEndDate publishEndDate: $publishEndDate
publishStartDate: $publishStartDate publishStartDate: $publishStartDate
relations: $relations relations: $relations
render: $render
scriptCss: $scriptCss scriptCss: $scriptCss
scriptJsLoad: $scriptJsLoad scriptJsLoad: $scriptJsLoad
scriptJsUnload: $scriptJsUnload scriptJsUnload: $scriptJsUnload
@ -336,6 +338,7 @@ export const usePageStore = defineStore('page', {
'publishStartDate', 'publishStartDate',
'publishState', 'publishState',
'relations', 'relations',
'render',
'scriptJsLoad', 'scriptJsLoad',
'scriptJsUnload', 'scriptJsUnload',
'scriptCss', 'scriptCss',
@ -401,6 +404,7 @@ export const usePageStore = defineStore('page', {
'publishStartDate', 'publishStartDate',
'publishState', 'publishState',
'relations', 'relations',
'render',
'scriptJsLoad', 'scriptJsLoad',
'scriptJsUnload', 'scriptJsUnload',
'scriptCss', 'scriptCss',

Loading…
Cancel
Save