mirror of
https://github.com/kremalicious/astro-redirect-from.git
synced 2024-12-04 15:04:28 +01:00
formatting fixes
This commit is contained in:
parent
448225dcd0
commit
d8bd20f370
@ -20,17 +20,19 @@ export async function getRedirects(
|
|||||||
const frontmatter = await getMarkdownFrontmatter(path.join(srcDir, file))
|
const frontmatter = await getMarkdownFrontmatter(path.join(srcDir, file))
|
||||||
let redirectFrom: string[] = []
|
let redirectFrom: string[] = []
|
||||||
|
|
||||||
if (frontmatter?.redirect_from){
|
if (frontmatter?.redirect_from) {
|
||||||
if (typeof frontmatter?.redirect_from === 'string') {
|
if (typeof frontmatter?.redirect_from === 'string') {
|
||||||
redirectFrom = [frontmatter.redirect_from]
|
redirectFrom = [frontmatter.redirect_from]
|
||||||
} else if (Array.isArray(frontmatter?.redirect_from)) {
|
} else if (Array.isArray(frontmatter?.redirect_from)) {
|
||||||
redirectFrom = frontmatter.redirect_from
|
redirectFrom = frontmatter.redirect_from
|
||||||
} else {
|
} 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)) {
|
if (isValidDomainRelativePath(redirect)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import path from 'node:path'
|
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
import type { AstroIntegration } from 'astro'
|
import type { AstroIntegration } from 'astro'
|
||||||
import { getRedirects } from './getRedirects.js'
|
import { getRedirects } from './getRedirects.js'
|
||||||
import { getMarkdownFiles, getSlugFromFilePath, writeJson } from './utils.js'
|
import { getMarkdownFiles, getSlugFromFilePath, writeJson } from './utils.js'
|
||||||
|
@ -3,8 +3,6 @@ import { createRedirect } from '../src/createRedirect'
|
|||||||
import { getRedirects } from '../src/getRedirects'
|
import { getRedirects } from '../src/getRedirects'
|
||||||
import { getMarkdownFiles, getSlugFromFilePath } from '../src/utils'
|
import { getMarkdownFiles, getSlugFromFilePath } from '../src/utils'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('getRedirects', async () => {
|
describe('getRedirects', async () => {
|
||||||
// handling this more as an integration test
|
// handling this more as an integration test
|
||||||
const srcDir = './test/__fixtures__/markdown'
|
const srcDir = './test/__fixtures__/markdown'
|
||||||
@ -23,7 +21,7 @@ describe('getRedirects', async () => {
|
|||||||
'/hello-astro-old': '/hello-astroooooo',
|
'/hello-astro-old': '/hello-astroooooo',
|
||||||
'/hello-astro-old-234837': '/hello-astroooooo',
|
'/hello-astro-old-234837': '/hello-astroooooo',
|
||||||
'/hello-world-old': '/posts/hello-world',
|
'/hello-world-old': '/posts/hello-world',
|
||||||
"/hello-once": "/posts/hello-once",
|
'/hello-once': '/posts/hello-once',
|
||||||
'/hello-world-old-234837': '/posts/hello-world',
|
'/hello-world-old-234837': '/posts/hello-world',
|
||||||
'/hello-markdown-old': '/hello-markdown',
|
'/hello-markdown-old': '/hello-markdown',
|
||||||
'/hello-markdown-old-234837': '/hello-markdown'
|
'/hello-markdown-old-234837': '/hello-markdown'
|
||||||
|
Loading…
Reference in New Issue
Block a user