1
0
mirror of https://github.com/kremalicious/astro-redirect-from.git synced 2024-11-22 09:57:03 +01:00

remove import.meta.env usage

This commit is contained in:
Matthias Kretschmann 2023-09-23 19:18:54 +01:00
parent 19a0da1204
commit 676d07eacb
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 11 additions and 4 deletions

View File

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

View File

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