mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
Refactor(server): share logic between server.js & generate.js (#856)
* nits too many comments * Refactor to blog.getPages * Refactor to getPost, fileToUrl, urlToFile * Refactor redirectcomponent generation for docs * nits & fix typo * Refactor to blog.getMetadata * Add test for getMetadata, fileToSUrl and urlToSource * use includes() and add 'markup' naming for function
This commit is contained in:
parent
bbfb4b09cb
commit
afec4bd47c
8 changed files with 249 additions and 214 deletions
|
@ -10,6 +10,7 @@ const {join} = require('path');
|
|||
const fs = require('fs-extra');
|
||||
const React = require('react');
|
||||
const env = require('./env.js');
|
||||
const {renderToStaticMarkupWithDoctype} = require('./renderUtils');
|
||||
const readMetadata = require('./readMetadata.js');
|
||||
const {insertTOC} = require('../core/toc.js');
|
||||
const {getPath} = require('../core/utils.js');
|
||||
|
@ -82,7 +83,7 @@ function replaceAssetsLink(oldContent) {
|
|||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function getComponent(rawContent, mdToHtml, metadata) {
|
||||
function getMarkup(rawContent, mdToHtml, metadata) {
|
||||
// generate table of contents
|
||||
let content = insertTOC(rawContent);
|
||||
|
||||
|
@ -93,7 +94,7 @@ function getComponent(rawContent, mdToHtml, metadata) {
|
|||
content = replaceAssetsLink(content);
|
||||
|
||||
const DocsLayout = require('../core/DocsLayout.js');
|
||||
return (
|
||||
return renderToStaticMarkupWithDoctype(
|
||||
<DocsLayout
|
||||
metadata={metadata}
|
||||
language={metadata.language}
|
||||
|
@ -103,9 +104,26 @@ function getComponent(rawContent, mdToHtml, metadata) {
|
|||
);
|
||||
}
|
||||
|
||||
function getRedirectMarkup(metadata) {
|
||||
if (!env.translation.enabled || !metadata.permalink.includes('docs/en')) {
|
||||
return null;
|
||||
}
|
||||
const Redirect = require('../core/Redirect.js');
|
||||
const redirectlink = getPath(metadata.permalink, siteConfig.cleanUrl);
|
||||
return renderToStaticMarkupWithDoctype(
|
||||
<Redirect
|
||||
metadata={metadata}
|
||||
language={metadata.language}
|
||||
config={siteConfig}
|
||||
redirect={siteConfig.baseUrl + redirectlink}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getComponent,
|
||||
getMarkup,
|
||||
getFile,
|
||||
getRedirectMarkup,
|
||||
mdToHtmlify,
|
||||
replaceAssetsLink,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue