diff --git a/src/resolvers/md2html.ts b/src/resolvers/md2html.ts index 6a01ab09..cb45da5c 100644 --- a/src/resolvers/md2html.ts +++ b/src/resolvers/md2html.ts @@ -88,7 +88,7 @@ const getFileProps = async (options: ResolverOptions) => { const tocBaseLang = tocBase?.split('/')[0]; const tocLang = configLangs?.includes(tocBaseLang as Lang) && tocBaseLang; - const lang = tocLang || configLang || Lang.RU; + const lang = tocLang || configLang || configLangs?.[0] || Lang.RU; const langs = configLangs?.length ? configLangs : [lang]; const props = { diff --git a/src/steps/processPages.ts b/src/steps/processPages.ts index ffea4691..c7fd4bd9 100644 --- a/src/steps/processPages.ts +++ b/src/steps/processPages.ts @@ -189,12 +189,16 @@ async function saveSinglePages() { } function saveRedirectPage(outputDir: string): void { - const {lang} = ArgvService.getConfig(); + const {lang, langs} = ArgvService.getConfig(); + + const redirectLang = lang || langs?.[0] || Lang.RU; + const redirectLangRelativePath = `./${redirectLang}/index.html`; const redirectPagePath = join(outputDir, 'index.html'); + const redirectLangPath = join(outputDir, redirectLangRelativePath); - if (!existsSync(redirectPagePath)) { - const content = generateStaticRedirect(lang || Lang.RU); + if (!existsSync(redirectPagePath) && existsSync(redirectLangPath)) { + const content = generateStaticRedirect(redirectLang, redirectLangRelativePath); writeFileSync(redirectPagePath, content); } } diff --git a/src/utils/redirect.ts b/src/utils/redirect.ts index e16b3e68..d39d329f 100644 --- a/src/utils/redirect.ts +++ b/src/utils/redirect.ts @@ -4,7 +4,7 @@ import {PluginService} from '../services'; import {join} from 'path'; import manifest from '@diplodoc/client/manifest'; -export function generateStaticRedirect(lang: Lang): string { +export function generateStaticRedirect(lang: Lang, link: string): string { const isRTL = RTL_LANGS.includes(lang); return ` @@ -12,7 +12,7 @@ export function generateStaticRedirect(lang: Lang): string {
- +