@docusaurus/utils
Advanced tools
Comparing version 2.0.0-alpha.37 to 2.0.0-alpha.38
@@ -44,2 +44,7 @@ /** | ||
export declare function normalizeUrl(rawUrls: string[]): string; | ||
/** | ||
* Alias filepath relative to site directory, very useful so that we don't expose user's site structure. | ||
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md | ||
*/ | ||
export declare function aliasedSitePath(filePath: string, siteDir: string): string; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -26,3 +26,13 @@ "use strict"; | ||
} | ||
const lastHash = fileHash.get(filepath); | ||
let lastHash = fileHash.get(filepath); | ||
// If file already exist but its not in runtime cache hash yet, | ||
// we try to calculate the content hash and then compare | ||
// This is to avoid unnecessary overwrite and we can reuse old file | ||
if (!lastHash && fs_extra_1.default.existsSync(filepath)) { | ||
const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8'); | ||
lastHash = crypto_1.createHash('md5') | ||
.update(lastContent) | ||
.digest('hex'); | ||
fileHash.set(filepath, lastHash); | ||
} | ||
const currentHash = crypto_1.createHash('md5') | ||
@@ -209,1 +219,11 @@ .update(content) | ||
exports.normalizeUrl = normalizeUrl; | ||
/** | ||
* Alias filepath relative to site directory, very useful so that we don't expose user's site structure. | ||
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md | ||
*/ | ||
function aliasedSitePath(filePath, siteDir) { | ||
const relativePath = path_1.default.relative(siteDir, filePath); | ||
// Cannot use path.join() as it resolves '../' and removes the '@site'. Let webpack loader resolve it. | ||
return `@site/${relativePath}`; | ||
} | ||
exports.aliasedSitePath = aliasedSitePath; |
{ | ||
"name": "@docusaurus/utils", | ||
"version": "2.0.0-alpha.37", | ||
"version": "2.0.0-alpha.38", | ||
"description": "Node utility functions for Docusaurus packages", | ||
@@ -23,3 +23,3 @@ "main": "./lib/index.js", | ||
}, | ||
"gitHead": "464d8e529a8a49be02f59ecc600cd5de3d1ef40f" | ||
"gitHead": "3bb251904bae3137cf2e08e845edc27519b3a7b2" | ||
} |
@@ -19,5 +19,18 @@ /** | ||
objectWithKeySorted, | ||
aliasedSitePath, | ||
} from '../index'; | ||
describe('load utils', () => { | ||
test('aliasedSitePath', () => { | ||
const asserts = { | ||
'user/website/docs/asd.md': '@site/docs/asd.md', | ||
'user/website/versioned_docs/foo/bar.md': | ||
'@site/versioned_docs/foo/bar.md', | ||
'user/docs/test.md': '@site/../docs/test.md', | ||
}; | ||
Object.keys(asserts).forEach(file => { | ||
expect(aliasedSitePath(file, 'user/website')).toBe(asserts[file]); | ||
}); | ||
}); | ||
test('posixPath', () => { | ||
@@ -24,0 +37,0 @@ const asserts = { |
@@ -30,3 +30,15 @@ /** | ||
const lastHash = fileHash.get(filepath); | ||
let lastHash = fileHash.get(filepath); | ||
// If file already exist but its not in runtime cache hash yet, | ||
// we try to calculate the content hash and then compare | ||
// This is to avoid unnecessary overwrite and we can reuse old file | ||
if (!lastHash && fs.existsSync(filepath)) { | ||
const lastContent = await fs.readFile(filepath, 'utf8'); | ||
lastHash = createHash('md5') | ||
.update(lastContent) | ||
.digest('hex'); | ||
fileHash.set(filepath, lastHash); | ||
} | ||
const currentHash = createHash('md5') | ||
@@ -244,1 +256,11 @@ .update(content) | ||
} | ||
/** | ||
* Alias filepath relative to site directory, very useful so that we don't expose user's site structure. | ||
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md | ||
*/ | ||
export function aliasedSitePath(filePath: string, siteDir: string) { | ||
const relativePath = path.relative(siteDir, filePath); | ||
// Cannot use path.join() as it resolves '../' and removes the '@site'. Let webpack loader resolve it. | ||
return `@site/${relativePath}`; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
324489
787