diff --git a/src/steps/processPages.ts b/src/steps/processPages.ts index 312fa3b5..10673df5 100644 --- a/src/steps/processPages.ts +++ b/src/steps/processPages.ts @@ -33,6 +33,7 @@ import { SINGLE_PAGE_DATA_FILENAME, SINGLE_PAGE_FILENAME, } from '../constants'; +import { generateStaticRedirect } from '../utils/redirect'; const singlePageResults: Record = {}; const singlePagePaths: Record> = {}; @@ -84,6 +85,11 @@ export async function processPages(outputBundlePath: string): Promise { if (singlePage) { await saveSinglePages(outputBundlePath); + } else { + saveRedirectPage({ + outputBundlePath, + outputDir: outputFolderPath, + }); } } @@ -180,6 +186,24 @@ async function saveSinglePages(outputBundlePath: string) { } } +function saveRedirectPage(pathData: { + outputBundlePath: string; + outputDir: string; +}): void { + const { + output: outputFolderPath, + lang, + } = ArgvService.getConfig(); + + const {outputBundlePath, outputDir} = pathData; + + const relativeOutputBundlePath = relative(outputFolderPath, outputBundlePath); + const redirectPagePath = join(outputDir, "index.html"); + const content = generateStaticRedirect(lang || Lang.RU, relativeOutputBundlePath); + + writeFileSync(redirectPagePath, content); +} + function savePageResultForSinglePage(pageProps: DocInnerProps, pathData: PathData): void { const {pathToFile, outputTocDir} = pathData; diff --git a/src/utils/redirect.ts b/src/utils/redirect.ts new file mode 100644 index 00000000..440bcdce --- /dev/null +++ b/src/utils/redirect.ts @@ -0,0 +1,41 @@ +import {Lang, RTL_LANGS} from '../constants'; +import {PluginService} from '../services'; + +import {join} from 'path'; +import manifest from '@diplodoc/client/manifest'; + +export function generateStaticRedirect( + lang: Lang, + pathToBundle: string, +): string { + const isRTL = RTL_LANGS.includes(lang); + + return ` + + + + + + + Redirect + + ${manifest.css + .filter((file: string) => isRTL === file.includes('.rtl.css')) + .map((target: string) => join(pathToBundle, target)) + .map((src: string) => ``) + .join('\n')} + ${PluginService.getHeadContent()} + + + + If you are not redirected automatically, follow this link to example. + + + `; +}