Skip to content

refactor!: spell extensions correctly #1204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2022
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
2 changes: 1 addition & 1 deletion playground/content/real-content/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Parsers and Transformers can be defined using `defineContentPlugin`:
```ts
export default defineContentPlugin({
name: 'plugin-name',
extentions: ['.md'],
extensions: ['.md'],
parse: async (id, content) => {},
transform: async content => {}
})
Expand Down
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ export default defineNuxtModule<ModuleOptions>({
// TODO: remove kit usage
templateUtils.importSources(contentContext.transformers),
`const transformers = [${contentContext.transformers.map(templateUtils.importName).join(', ')}]`,
'export const getParser = (ext) => transformers.find(p => ext.match(new RegExp(p.extentions.join("|"), "i")) && p.parse)',
'export const getTransformers = (ext) => transformers.filter(p => ext.match(new RegExp(p.extentions.join("|"), "i")) && p.transform)',
'export const getParser = (ext) => transformers.find(p => ext.match(new RegExp(p.extensions.join("|"), "i")) && p.parse)',
'export const getTransformers = (ext) => transformers.filter(p => ext.match(new RegExp(p.extensions.join("|"), "i")) && p.transform)',
'export default () => {}'
].join('\n')
})
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/transformers/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRuntimeConfig } from '#imports'

export default {
name: 'csv',
extentions: ['.csv'],
extensions: ['.csv'],
parse: async (_id, content) => {
const config = { ...useRuntimeConfig().content?.csv || {} }

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/transformers/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import destr from 'destr'

export default {
name: 'Json',
extentions: ['.json', '.json5'],
extensions: ['.json', '.json5'],
parse: async (_id, content) => {
let parsed = content

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/transformers/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const importPlugin = async (p: [string, any]) => ([

export default {
name: 'markdown',
extentions: ['.md'],
extensions: ['.md'],
parse: async (_id, content) => {
const config: MarkdownOptions = { ...useRuntimeConfig().content?.markdown || {} }
config.rehypePlugins = await Promise.all((config.rehypePlugins || []).map(importPlugin))
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/transformers/path-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const describeId = (_id: string) => {

export default {
name: 'path-meta',
extentions: ['.*'],
extensions: ['.*'],
transform (content) {
const { locales, defaultLocale } = useRuntimeConfig().content || {}
const { _source, _file, _path, _extension } = describeId(content._id)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/transformers/shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const withContentBase = (url: string) => {

export default {
name: 'markdown',
extentions: ['.md'],
extensions: ['.md'],
transform: async (content) => {
const codeBlocks = []
visit(
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/transformers/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFrontMatter } from '../../markdown-parser'

export default {
name: 'Yaml',
extentions: ['.yml', '.yaml'],
extensions: ['.yml', '.yaml'],
parse: async (_id, content) => {
const { data } = await parseFrontMatter(`---\n${content}\n---`)

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface Toc {

export interface ContentTransformer {
name: string
extentions: string[]
extensions: string[]
parse?(id: string, content: string): Promise<ParsedContent> | ParsedContent
transform?: ((content: ParsedContent) => Promise<ParsedContent>) | ((content: ParsedContent) => ParsedContent)
}
Expand Down