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
2 changes: 2 additions & 0 deletions src/module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ export default defineNuxtModule<ModuleOptions>({
},
// @ts-expect-error Autogenerated type does not match with options
repository: options.repository,
// @ts-expect-error Autogenerated type does not match with options
markdown: nuxt.options.content?.build?.markdown || {},
}

nuxt.options.vite = defu(nuxt.options.vite, {
Expand Down
7 changes: 7 additions & 0 deletions src/module/src/runtime/composables/useMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import { kebabCase } from 'scule'
interface Meta {
components: ComponentMeta[]
highlightTheme: { default: string, dark?: string, light?: string }
markdownConfig: {
contentHeading?: boolean
}
}

const defaultMeta: Meta = {
components: [],
highlightTheme: { default: 'github-light', dark: 'github-dark' },
markdownConfig: {},
}

export const useHostMeta = createSharedComposable(() => {
const components = shallowRef<ComponentMeta[]>([])
const highlightTheme = shallowRef<Meta['highlightTheme']>()
const markdownConfig = shallowRef<Meta['markdownConfig']>()

async function fetch() {
// TODO: look into this approach and consider possible refactors
Expand All @@ -24,6 +29,7 @@ export const useHostMeta = createSharedComposable(() => {
}).catch(() => defaultMeta)

highlightTheme.value = data.highlightTheme
markdownConfig.value = data.markdownConfig

// Markdown elements to exclude (in kebab-case)
const markdownElements = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'p', 'li', 'ul', 'ol', 'blockquote', 'code', 'code-block', 'image', 'video', 'link', 'hr', 'img', 'pre', 'em', 'bold', 'italic', 'strike', 'strong', 'tr', 'thead', 'tbody', 'tfoot', 'th', 'td'])
Expand Down Expand Up @@ -110,5 +116,6 @@ export const useHostMeta = createSharedComposable(() => {
fetch,
components,
highlightTheme,
markdownConfig,
}
})
4 changes: 3 additions & 1 deletion src/module/src/runtime/server/routes/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ interface NuxtComponentMeta {
}

export default eventHandler(async (event) => {
const config = useRuntimeConfig()
if (!import.meta.dev) {
const session = await useSession(event, {
name: 'studio-session',
password: useRuntimeConfig(event).studio?.auth?.sessionSecret,
password: config.studio?.auth?.sessionSecret,
})

if (!session?.data?.user) {
Expand All @@ -42,6 +43,7 @@ export default eventHandler(async (event) => {
})

return {
markdownConfig: config.studio.markdown || {},
highlightTheme: highlight?.theme || { default: 'github-light', dark: 'github-dark', light: 'github-light' },
components: mappedComponents,
}
Expand Down
3 changes: 2 additions & 1 deletion src/module/src/runtime/utils/document/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ export async function generateDocumentFromJSONContent(id: string, content: strin
}

export async function generateDocumentFromMarkdownContent(id: string, content: string, options: MarkdownParsingOptions = { compress: true }): Promise<DatabaseItem> {
const markdownConfig = useHostMeta().markdownConfig.value
const document = await parseMarkdown(content, {
contentHeading: options.collectionType === 'page',
contentHeading: markdownConfig?.contentHeading !== false ? options.collectionType === 'page' : false,
highlight: {
theme: useHostMeta().highlightTheme.value,
},
Expand Down
Loading