1
0
mirror of https://github.com/kremalicious/astro-redirect-from.git synced 2024-12-03 14:34:29 +01:00

formatting fixes

This commit is contained in:
Matthias Kretschmann 2024-08-12 12:54:20 +02:00
parent 448225dcd0
commit d8bd20f370
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 7 additions and 7 deletions

View File

@ -20,17 +20,19 @@ export async function getRedirects(
const frontmatter = await getMarkdownFrontmatter(path.join(srcDir, file))
let redirectFrom: string[] = []
if (frontmatter?.redirect_from){
if (frontmatter?.redirect_from) {
if (typeof frontmatter?.redirect_from === 'string') {
redirectFrom = [frontmatter.redirect_from]
} else if (Array.isArray(frontmatter?.redirect_from)) {
redirectFrom = frontmatter.redirect_from
} else {
logger.warn(`Unexpected type ${typeof frontmatter?.redirect_from} for redirect_from in file: ${file}`)
logger.warn(
`Unexpected type ${typeof frontmatter?.redirect_from} for redirect_from in file: ${file}`
)
}
}
redirectFrom = redirectFrom.filter(redirect => {
redirectFrom = redirectFrom.filter((redirect) => {
if (isValidDomainRelativePath(redirect)) {
return true
}

View File

@ -1,5 +1,5 @@
import path from 'node:path'
import fs from 'node:fs'
import path from 'node:path'
import type { AstroIntegration } from 'astro'
import { getRedirects } from './getRedirects.js'
import { getMarkdownFiles, getSlugFromFilePath, writeJson } from './utils.js'

View File

@ -3,8 +3,6 @@ import { createRedirect } from '../src/createRedirect'
import { getRedirects } from '../src/getRedirects'
import { getMarkdownFiles, getSlugFromFilePath } from '../src/utils'
describe('getRedirects', async () => {
// handling this more as an integration test
const srcDir = './test/__fixtures__/markdown'
@ -23,7 +21,7 @@ describe('getRedirects', async () => {
'/hello-astro-old': '/hello-astroooooo',
'/hello-astro-old-234837': '/hello-astroooooo',
'/hello-world-old': '/posts/hello-world',
"/hello-once": "/posts/hello-once",
'/hello-once': '/posts/hello-once',
'/hello-world-old-234837': '/posts/hello-world',
'/hello-markdown-old': '/hello-markdown',
'/hello-markdown-old-234837': '/hello-markdown'