mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-24 21:48:02 +02:00
Refactor + add more tests (Part 1) (#847)
* Refactor mdToHtml out * Refactor routing + move it to server instead of core * Refactor & Add more tests for server utils * Refactor isSeparateCss function from server & generate * Refactor insertTableOfContents from server & generate + add tests * undo small nits
This commit is contained in:
parent
a7a214fb3a
commit
defcbcc8ee
14 changed files with 322 additions and 235 deletions
|
@ -63,6 +63,27 @@ function extractMetadata(content) {
|
|||
return {metadata, rawContent: both.content};
|
||||
}
|
||||
|
||||
// mdToHtml is a map from a markdown file name to its html link, used to
|
||||
// change relative markdown links that work on GitHub into actual site links
|
||||
function mdToHtml(Metadata, baseUrl) {
|
||||
const result = {};
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
const metadata = Metadata[id];
|
||||
if (metadata.language !== 'en' || metadata.original_id) {
|
||||
return;
|
||||
}
|
||||
let htmlLink = baseUrl + metadata.permalink.replace('/next/', '/');
|
||||
if (htmlLink.includes('/docs/en/')) {
|
||||
htmlLink = htmlLink.replace('/docs/en/', '/docs/en/VERSION/');
|
||||
} else {
|
||||
htmlLink = htmlLink.replace('/docs/', '/docs/VERSION/');
|
||||
}
|
||||
result[metadata.source] = htmlLink;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
extractMetadata,
|
||||
mdToHtml,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue