Skip to content
Open
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
1 change: 0 additions & 1 deletion src/app/src/types/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { CollectionType } from '@nuxt/content'
export interface MarkdownParsingOptions {
compress?: boolean
collectionType?: CollectionType
preserveLinkAttributes?: boolean
}

export interface SyntaxHighlightTheme {
Expand Down
2 changes: 1 addition & 1 deletion src/module/src/runtime/utils/document/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { generateDocumentFromContent } from './generate'
import { removeLastStylesFromTree } from './tree'

export async function isDocumentMatchingContent(content: string, document: DatabaseItem): Promise<boolean> {
const generatedDocument = await generateDocumentFromContent(document.id, content, { compress: true, preserveLinkAttributes: true }) as DatabaseItem
const generatedDocument = await generateDocumentFromContent(document.id, content, { compress: true }) as DatabaseItem

if (generatedDocument.extension === ContentFileExtension.Markdown) {
const { body: generatedBody, ...generatedDocumentData } = generatedDocument
Expand Down
18 changes: 1 addition & 17 deletions src/module/src/runtime/utils/document/generate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { MarkdownRoot } from '@nuxt/content'
import type { MDCElement, MDCRoot } from '@nuxtjs/mdc'
import type { MDCRoot } from '@nuxtjs/mdc'
import type { DatabaseItem, DatabasePageItem, MarkdownParsingOptions } from 'nuxt-studio/app'
import type { Node } from 'unist'
import { consola } from 'consola'
import { ContentFileExtension } from '../../types/content'
import { parseMarkdown } from '@nuxtjs/mdc/runtime/parser/index'
import { stringifyMarkdown } from '@nuxtjs/mdc/runtime'
import { visit } from 'unist-util-visit'
import { compressTree, decompressTree } from '@nuxt/content/runtime'
import destr from 'destr'
import { parseFrontMatter, stringifyFrontMatter } from 'remark-mdc'
Expand Down Expand Up @@ -109,14 +107,6 @@ export async function generateDocumentFromMarkdownContent(id: string, content: s
},
})

// Remove nofollow from links (skip when preserving attributes for comparison purposes)
if (!options.preserveLinkAttributes) {
visit(document.body, (node: unknown) => (node as MDCElement).type === 'element' && (node as MDCElement).tag === 'a', (node: unknown) => {
// TODO: handle rel custom properties
Reflect.deleteProperty((node as MDCElement).props!, 'rel')
})
}

let body = document.body as never as MarkdownRoot
if (options.compress && document.body.type === 'root') {
body = compressTree(document.body)
Expand Down Expand Up @@ -177,12 +167,6 @@ export async function generateContentFromMarkdownDocument(document: DatabaseItem
// @ts-expect-error todo fix MarkdownRoot/MDCRoot conversion in MDC module
const body = document.body!.type === 'minimark' ? decompressTree(document.body) : (document.body as MDCRoot)

// Remove nofollow from links
visit(body, (node: Node) => (node as MDCElement).type === 'element' && (node as MDCElement).tag === 'a', (node: Node) => {
// TODO: handle rel custom properties
Reflect.deleteProperty((node as MDCElement).props!, 'rel')
})

const markdown = await stringifyMarkdown(body, cleanDataKeys(document), {
frontMatter: {
options: {
Expand Down