Skip to content

Commit

Permalink
feat: add disableHtmlExt config feature to links and redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
makamekm committed Apr 26, 2024
1 parent 98ca605 commit 7e65877
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export const REGEXP_INCLUDE_FILE_PATH = /(?<=[(]).+(?=[)])/g;
// Regexp result: authorLogin
export const REGEXP_AUTHOR = /(?<=author:\s).+(?=\r?\n)/g;

export const REGEXP_EXT_HTML = /(\.html)$/gi;

export const MIN_CHUNK_SIZE = Number(process.env.MIN_CHUNK_SIZE) || 1000;
export const WORKERS_COUNT = Number(process.env.WORKERS_COUNT) || os.cpus().length - 1;
export const PAGE_PROCESS_CONCURRENCY = Number(process.env.PAGE_PROCESS_CONCURRENCY) || 500;
Expand Down
8 changes: 6 additions & 2 deletions src/steps/processPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import shell from 'shelljs';
import {
Lang,
PAGE_PROCESS_CONCURRENCY,
REGEXP_EXT_HTML,
ResourceType,
SINGLE_PAGE_DATA_FILENAME,
SINGLE_PAGE_FILENAME,
Expand Down Expand Up @@ -189,15 +190,18 @@ async function saveSinglePages() {
}

function saveRedirectPage(outputDir: string): void {
const {lang, langs} = ArgvService.getConfig();
const {lang, langs, disableHtmlExt} = ArgvService.getConfig();

const redirectLang = lang || langs?.[0] || Lang.RU;
const redirectLangRelativePath = `./${redirectLang}/index.html`;
let redirectLangRelativePath = `./${redirectLang}/index.html`;

const redirectPagePath = join(outputDir, 'index.html');
const redirectLangPath = join(outputDir, redirectLangRelativePath);

if (!existsSync(redirectPagePath) && existsSync(redirectLangPath)) {
if (disableHtmlExt) {
redirectLangRelativePath = redirectLangRelativePath.replace(REGEXP_EXT_HTML, '');
}
const content = generateStaticRedirect(redirectLang, redirectLangRelativePath);
writeFileSync(redirectPagePath, content);
}
Expand Down

0 comments on commit 7e65877

Please sign in to comment.