Skip to content

Commit

Permalink
Merge pull request newrelic#16229 from newrelic/tabatha/add-install-r…
Browse files Browse the repository at this point in the history
…edirects

add check for install config yaml redirects
  • Loading branch information
LizBaker authored Feb 20, 2024
2 parents 730beb9 + bbd415d commit 4ea772e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scripts/createNetlifyRedirects.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { frontmatter } from './utils/frontmatter.js';
import { mkdir, readFile, writeFile } from 'fs/promises';
import { readFileSync } from 'fs';
import { glob } from 'glob10';
import yaml from 'js-yaml';
import { join } from 'path';

if (process.env.BUILD_LANG !== 'en') {
Expand All @@ -17,6 +19,7 @@ const redirects = new Map();
const LOCALES = ['jp', 'kr'];

const mdxPaths = await glob('src/content/docs/**/*.{md,mdx}');
const installYamlPaths = await glob('src/install/config/**/*.yaml');

const urlFromFsPath = (fspath) =>
fspath.replace(/src\/content/, '').replace(/\.mdx?$/, '');
Expand Down Expand Up @@ -44,7 +47,6 @@ for (const redirect of manualRedirects) {
redirects.set(redirect.from, redirect.to);
}

// MDX frontmatter redirects
for (const path of mdxPaths) {
const contents = await readFile(join(process.cwd(), path), 'utf-8');
const to = urlFromFsPath(path);
Expand All @@ -59,6 +61,20 @@ for (const path of mdxPaths) {
localizedRedirects.forEach((from) => redirects.set(from, localizedTo));
}
}
// install config redirects
for (const path of installYamlPaths) {
const contents = await yaml.load(readFileSync(join(process.cwd(), path)));
const to = `/install/${contents.agentName}`;
const enRedirects = contents.redirects ?? [];

enRedirects.forEach((from) => redirects.set(from, to));

for (const locale of LOCALES) {
const localizedTo = `/${locale}${to}`;
const localizedRedirects = enRedirects.map((from) => `/${locale}${from}`);
localizedRedirects.forEach((from) => redirects.set(from, localizedTo));
}
}

const redirectsList = Array.from(redirects.entries())
.map(([from, to]) => ({
Expand Down

0 comments on commit 4ea772e

Please sign in to comment.