Skip to content

Commit

Permalink
options init refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Sep 24, 2023
1 parent 7fb9b2f commit d9e967a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -28,16 +29,16 @@ 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
}

const redirects = await getRedirects(
markdownFiles,
contentDirPath,
getSlug,
_contentDirPath,
_getSlug,
command
)
if (!redirects || !Object.keys(redirects).length) {
Expand Down

0 comments on commit d9e967a

Please sign in to comment.