diff --git a/src/resolvers/md2html.ts b/src/resolvers/md2html.ts index a0d1382a..43f1f7cb 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 { - + Redirect - If you are not redirected automatically, follow this link to example. + If you are not redirected automatically, follow this link to example. `; diff --git a/tests/e2e/__snapshots__/rtl.spec.ts.snap b/tests/e2e/__snapshots__/rtl.spec.ts.snap index 49759db2..6e2e6f26 100644 --- a/tests/e2e/__snapshots__/rtl.spec.ts.snap +++ b/tests/e2e/__snapshots__/rtl.spec.ts.snap @@ -4,8 +4,8 @@ exports[`Generate html document with correct lang and dir attributes. Load corre exports[`Generate html document with correct lang and dir attributes. Load correct bundles. documentation with only one rtl lang 2`] = ` - @@ -23,11 +23,11 @@ exports[`Generate html document with correct lang and dir attributes. Load corre @@ -35,7 +35,7 @@ exports[`Generate html document with correct lang and dir attributes. Load corre @@ -88,7 +88,7 @@ exports[`Generate html document with correct lang and dir attributes. Load corre window.STATIC_CONTENT = false window.__DATA__ = {"data":{"leading":false,"toc":{"title":"Documentation","href":"index.html","items":[{"name":"Documentation","href":"page.html","id":"Documentation-RANDOM"}],"base":"."},"meta":{"metadata":[],"style":[],"script":[]},"assets":[],"headings":[],"title":"","includes":[],"html":"

תיעוד -

/n"},"router":{"pathname":"page.html"},"lang":"ru","langs":["he"]}; +

/n"},"router":{"pathname":"page.html"},"lang":"he","langs":["he"]}; If you are not redirected automatically, follow this - + link to example .