From d9e967aa31e6f9cbcb7d03e51fb1a70cf1b62831 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sun, 24 Sep 2023 11:50:50 +0100 Subject: [PATCH] options init refactor --- src/index.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 358534c..76119c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,11 +12,12 @@ export type PluginOptions = { export type Redirects = { [old: string]: string } -export default function astroRedirectFrom({ - contentDir = 'src/pages/', - getSlug = getSlugFromFilePath -}: PluginOptions): AstroIntegration { - const contentDirPath = path.join(process.cwd(), contentDir) +export default function astroRedirectFrom( + options?: PluginOptions +): AstroIntegration { + const _contentDir = options?.contentDir || 'src/pages/' + const _getSlug = options?.getSlug || getSlugFromFilePath + const _contentDirPath = path.join(process.cwd(), _contentDir) return { name: 'redirect-from', @@ -28,7 +29,7 @@ export default function astroRedirectFrom({ logger }) => { try { - const markdownFiles = await getMarkdownFiles(contentDirPath) + const markdownFiles = await getMarkdownFiles(_contentDirPath) if (!markdownFiles?.length) { logger.warn('No markdown files found') return @@ -36,8 +37,8 @@ export default function astroRedirectFrom({ const redirects = await getRedirects( markdownFiles, - contentDirPath, - getSlug, + _contentDirPath, + _getSlug, command ) if (!redirects || !Object.keys(redirects).length) {