mirror of
https://github.com/kremalicious/astro-redirect-from.git
synced 2025-02-14 21:10:35 +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(
|
export async function getRedirects(
|
||||||
files: string[],
|
files: string[],
|
||||||
srcDir: string,
|
srcDir: string,
|
||||||
getSlug: (filePath: string) => string
|
getSlug: (filePath: string) => string,
|
||||||
|
command: 'dev' | 'build' | 'preview'
|
||||||
) {
|
) {
|
||||||
const redirects: Redirects = {}
|
const redirects: Redirects = {}
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ export async function getRedirects(
|
|||||||
if (
|
if (
|
||||||
!frontmatter ||
|
!frontmatter ||
|
||||||
!redirectFrom ||
|
!redirectFrom ||
|
||||||
(import.meta.env.PROD && frontmatter.draft === true)
|
(command === 'build' && frontmatter.draft === true)
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
10
src/index.ts
10
src/index.ts
@ -21,7 +21,12 @@ export default function astroRedirectFrom({
|
|||||||
return {
|
return {
|
||||||
name: 'redirect-from',
|
name: 'redirect-from',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': async ({ config, updateConfig, logger }) => {
|
'astro:config:setup': async ({
|
||||||
|
config,
|
||||||
|
command,
|
||||||
|
updateConfig,
|
||||||
|
logger
|
||||||
|
}) => {
|
||||||
try {
|
try {
|
||||||
const markdownFiles = await getMarkdownFiles(contentDirPath)
|
const markdownFiles = await getMarkdownFiles(contentDirPath)
|
||||||
if (!markdownFiles?.length) {
|
if (!markdownFiles?.length) {
|
||||||
@ -32,7 +37,8 @@ export default function astroRedirectFrom({
|
|||||||
const redirects = await getRedirects(
|
const redirects = await getRedirects(
|
||||||
markdownFiles,
|
markdownFiles,
|
||||||
contentDirPath,
|
contentDirPath,
|
||||||
getSlug
|
getSlug,
|
||||||
|
command
|
||||||
)
|
)
|
||||||
if (!redirects || !Object.keys(redirects).length) {
|
if (!redirects || !Object.keys(redirects).length) {
|
||||||
logger.info('No redirects found in markdown files')
|
logger.info('No redirects found in markdown files')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user