mirror of
https://github.com/kremalicious/astro-redirect-from.git
synced 2024-12-22 09:23:21 +01:00
remove import.meta.env usage
This commit is contained in:
parent
19a0da1204
commit
676d07eacb
@ -5,7 +5,8 @@ import { getMarkdownFrontmatter } from './utils.js'
|
||||
export async function getRedirects(
|
||||
files: string[],
|
||||
srcDir: string,
|
||||
getSlug: (filePath: string) => string
|
||||
getSlug: (filePath: string) => string,
|
||||
command: 'dev' | 'build' | 'preview'
|
||||
) {
|
||||
const redirects: Redirects = {}
|
||||
|
||||
@ -15,7 +16,7 @@ export async function getRedirects(
|
||||
if (
|
||||
!frontmatter ||
|
||||
!redirectFrom ||
|
||||
(import.meta.env.PROD && frontmatter.draft === true)
|
||||
(command === 'build' && frontmatter.draft === true)
|
||||
)
|
||||
continue
|
||||
|
||||
|
10
src/index.ts
10
src/index.ts
@ -21,7 +21,12 @@ export default function astroRedirectFrom({
|
||||
return {
|
||||
name: 'redirect-from',
|
||||
hooks: {
|
||||
'astro:config:setup': async ({ config, updateConfig, logger }) => {
|
||||
'astro:config:setup': async ({
|
||||
config,
|
||||
command,
|
||||
updateConfig,
|
||||
logger
|
||||
}) => {
|
||||
try {
|
||||
const markdownFiles = await getMarkdownFiles(contentDirPath)
|
||||
if (!markdownFiles?.length) {
|
||||
@ -32,7 +37,8 @@ export default function astroRedirectFrom({
|
||||
const redirects = await getRedirects(
|
||||
markdownFiles,
|
||||
contentDirPath,
|
||||
getSlug
|
||||
getSlug,
|
||||
command
|
||||
)
|
||||
if (!redirects || !Object.keys(redirects).length) {
|
||||
logger.info('No redirects found in markdown files')
|
||||
|
Loading…
Reference in New Issue
Block a user