fix(v2): truncate docuhash return value in order to avoid ERRNAMETOOLONG error (#4899)

* fix: truncate docuhash return value in order to avoid ERRNAMETOOLONG error

* chore: add deep file path test page to website

* refactor: reorganize docuHash/pathUtils code and tests

* chore: git support longpaths on v2 windows tests workflow

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Lucas Correia 2021-06-15 13:39:06 -03:00 committed by GitHub
parent 3d95a3e6b1
commit 34411e12e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 202 additions and 50 deletions

View file

@ -8,7 +8,7 @@
import chalk from 'chalk';
import path from 'path';
import {createHash} from 'crypto';
import {camelCase, kebabCase, mapValues} from 'lodash';
import {camelCase, mapValues} from 'lodash';
import escapeStringRegexp from 'escape-string-regexp';
import fs from 'fs-extra';
import {URL} from 'url';
@ -22,6 +22,8 @@ import {
import resolvePathnameUnsafe from 'resolve-pathname';
import {posixPath as posixPathImport} from './posixPath';
import {simpleHash} from './pathUtils';
import {docuHash} from './docuHash';
export const posixPath = posixPathImport;
@ -29,6 +31,8 @@ export * from './codeTranslationsUtils';
export * from './markdownParser';
export * from './markdownLinks';
export * from './escapePath';
export * from './docuHash';
export {simpleHash} from './pathUtils';
const fileHash = new Map();
export async function generate(
@ -98,22 +102,6 @@ export function encodePath(userpath: string): string {
.join('/');
}
export function simpleHash(str: string, length: number): string {
return createHash('md5').update(str).digest('hex').substr(0, length);
}
/**
* Given an input string, convert to kebab-case and append a hash.
* Avoid str collision.
*/
export function docuHash(str: string): string {
if (str === '/') {
return 'index';
}
const shortHash = simpleHash(str, 3);
return `${kebabCase(str)}-${shortHash}`;
}
/**
* Convert first string character to the upper case.
* E.g: docusaurus -> Docusaurus