@docusaurus/utils
Advanced tools
Comparing version 2.0.0-alpha.6 to 2.0.0-alpha.7
{ | ||
"name": "@docusaurus/utils", | ||
"version": "2.0.0-alpha.6", | ||
"version": "2.0.0-alpha.7", | ||
"description": "Node utility functions for Docusaurus packages", | ||
@@ -16,3 +16,3 @@ "main": "src/index.js", | ||
}, | ||
"gitHead": "d097f73285d275ce9fc19d40801f02a5c913b616" | ||
"gitHead": "1ce4195f1498b966df4f3d3e823bf386fd9ba424" | ||
} |
@@ -36,3 +36,3 @@ /** | ||
const asserts = { | ||
'/': 'Index', | ||
'/': 'index', | ||
'/foo-bar': 'FooBar096', | ||
@@ -55,3 +55,3 @@ '/foo/bar': 'FooBar1Df', | ||
'': '-d41', | ||
'/': 'Index', | ||
'/': 'index', | ||
'/foo-bar': 'foo-bar-096', | ||
@@ -86,3 +86,3 @@ '/foo/bar': 'foo-bar-1df', | ||
test('genChunkName', () => { | ||
const asserts = { | ||
let asserts = { | ||
'/docs/adding-blog': 'docs-adding-blog-062', | ||
@@ -100,2 +100,16 @@ '/docs/versioning': 'docs-versioning-8a8', | ||
}); | ||
// Don't allow different chunk name for same path. | ||
expect(genChunkName('path/is/similar', 'oldPrefix')).toEqual( | ||
genChunkName('path/is/similar', 'newPrefix'), | ||
); | ||
// Even with same preferred name, still different chunk name for different path | ||
asserts = { | ||
'/blog/1': 'blog-85-f-089', | ||
'/blog/2': 'blog-353-489', | ||
}; | ||
Object.keys(asserts).forEach(str => { | ||
expect(genChunkName(str, undefined, 'blog')).toBe(asserts[str]); | ||
}); | ||
}); | ||
@@ -102,0 +116,0 @@ |
@@ -50,3 +50,3 @@ /** | ||
if (str === '/') { | ||
return 'Index'; | ||
return 'index'; | ||
} | ||
@@ -67,3 +67,3 @@ const shortHash = createHash('md5') | ||
if (pagePath === '/') { | ||
return 'Index'; | ||
return 'index'; | ||
} | ||
@@ -93,5 +93,19 @@ const pageHash = docuHash(pagePath); | ||
function genChunkName(str, prefix) { | ||
const name = str === '/' ? 'index' : docuHash(str); | ||
return prefix ? `${prefix}---${name}` : name; | ||
const chunkNameCache = new Map(); | ||
function genChunkName(modulePath, prefix, preferredName) { | ||
let chunkName = chunkNameCache.get(modulePath); | ||
if (!chunkName) { | ||
let str = modulePath; | ||
if (preferredName) { | ||
const shortHash = createHash('md5') | ||
.update(modulePath) | ||
.digest('hex') | ||
.substr(0, 3); | ||
str = `${preferredName}${shortHash}`; | ||
} | ||
const name = str === '/' ? 'index' : docuHash(str); | ||
chunkName = prefix ? `${prefix}---${name}` : name; | ||
chunkNameCache.set(modulePath, chunkName); | ||
} | ||
return chunkName; | ||
} | ||
@@ -98,0 +112,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
615640
384