1
0
mirror of https://github.com/kremalicious/astro-redirect-from.git synced 2024-12-22 09:23:21 +01:00

options init refactor

This commit is contained in:
Matthias Kretschmann 2023-09-24 11:50:50 +01:00
parent 7fb9b2f60d
commit d9e967aa31
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -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) {