Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/app/src/components/content/ContentEditorCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,21 @@ watch(showAutomaticFormattingDiff, async (show) => {

// Trigger on document changes
watch(() => document.value?.id + '-' + props.draftItem.version, async () => {
if (document.value?.body) {
if (document.value) {
setContent(document.value)
}
}, { immediate: true })

async function setContent(document: DatabasePageItem) {
const contentFromDocument = host.document.generate.contentFromDocument
const md = await contentFromDocument(document) || ''
content.value = md
setEditorContent(md, true)
const generateContentFromDocument = host.document.generate.contentFromDocument
const generatedContent = await generateContentFromDocument(document) || ''
content.value = generatedContent
setEditorContent(generatedContent, true)
currentDocumentId.value = document.id

isAutomaticFormattingDetected.value = false
if (props.draftItem.original && props.draftItem.remoteFile?.content) {
const localOriginal = await contentFromDocument(props.draftItem.original as DatabaseItem) as string
const localOriginal = await generateContentFromDocument(props.draftItem.original as DatabaseItem) as string
const remoteOriginal = props.draftItem.remoteFile.encoding === 'base64' ? fromBase64ToUTF8(props.draftItem.remoteFile.content!) : props.draftItem.remoteFile.content!

isAutomaticFormattingDetected.value = !areContentEqual(localOriginal, remoteOriginal)
Expand Down
9 changes: 7 additions & 2 deletions src/module/src/runtime/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,19 @@ export async function generateDocumentFromYAMLContent(id: string, content: strin
parsed = { body: data }
}

return {
const document = {
id,
extension: getFileExtension(id),
stem: generateStemFromId(id),
meta: {},
...parsed,
body: parsed.body || parsed,
} as DatabaseItem

if (parsed.body) {
document.body = parsed.body
}

return document
}

export async function generateDocumentFromJSONContent(id: string, content: string): Promise<DatabaseItem> {
Expand Down
Loading