From b29473d36985ce541dfe614c2b76b3b77ae2474c Mon Sep 17 00:00:00 2001 From: Tabatha Zeitke Date: Tue, 20 Feb 2024 16:43:02 -0600 Subject: [PATCH 1/2] add check for install config yaml redirects --- scripts/createNetlifyRedirects.mjs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/createNetlifyRedirects.mjs b/scripts/createNetlifyRedirects.mjs index 4770c9b0052..adc2bcfbd34 100644 --- a/scripts/createNetlifyRedirects.mjs +++ b/scripts/createNetlifyRedirects.mjs @@ -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') { @@ -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?$/, ''); @@ -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); @@ -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(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]) => ({ From bbd415d268b2580a4cddc2abd64c74cf3eb91e2d Mon Sep 17 00:00:00 2001 From: Tabatha Zeitke Date: Tue, 20 Feb 2024 16:48:04 -0600 Subject: [PATCH 2/2] add join to readFileSync --- scripts/createNetlifyRedirects.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/createNetlifyRedirects.mjs b/scripts/createNetlifyRedirects.mjs index adc2bcfbd34..8df5ca8b047 100644 --- a/scripts/createNetlifyRedirects.mjs +++ b/scripts/createNetlifyRedirects.mjs @@ -63,7 +63,7 @@ for (const path of mdxPaths) { } // install config redirects for (const path of installYamlPaths) { - const contents = await yaml.load(readFileSync(path)); + const contents = await yaml.load(readFileSync(join(process.cwd(), path))); const to = `/install/${contents.agentName}`; const enRedirects = contents.redirects ?? [];