1
0
mirror of https://github.com/kremalicious/astro-redirect-from.git synced 2024-11-25 20:03:12 +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 type Redirects = { [old: string]: string }
export default function astroRedirectFrom({ export default function astroRedirectFrom(
contentDir = 'src/pages/', options?: PluginOptions
getSlug = getSlugFromFilePath ): AstroIntegration {
}: PluginOptions): AstroIntegration { const _contentDir = options?.contentDir || 'src/pages/'
const contentDirPath = path.join(process.cwd(), contentDir) const _getSlug = options?.getSlug || getSlugFromFilePath
const _contentDirPath = path.join(process.cwd(), _contentDir)
return { return {
name: 'redirect-from', name: 'redirect-from',
@ -28,7 +29,7 @@ export default function astroRedirectFrom({
logger logger
}) => { }) => {
try { try {
const markdownFiles = await getMarkdownFiles(contentDirPath) const markdownFiles = await getMarkdownFiles(_contentDirPath)
if (!markdownFiles?.length) { if (!markdownFiles?.length) {
logger.warn('No markdown files found') logger.warn('No markdown files found')
return return
@ -36,8 +37,8 @@ export default function astroRedirectFrom({
const redirects = await getRedirects( const redirects = await getRedirects(
markdownFiles, markdownFiles,
contentDirPath, _contentDirPath,
getSlug, _getSlug,
command command
) )
if (!redirects || !Object.keys(redirects).length) { if (!redirects || !Object.keys(redirects).length) {