mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-24 21:48:02 +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
|
@ -14,6 +14,7 @@ const glob = require('glob');
|
|||
const metadataUtils = require('./metadataUtils');
|
||||
|
||||
const env = require('./env.js');
|
||||
const blog = require('./blog.js');
|
||||
|
||||
const siteConfig = require(`${CWD}/siteConfig.js`);
|
||||
const versionFallback = require('./versionFallback.js');
|
||||
|
@ -313,27 +314,7 @@ function generateMetadataBlog() {
|
|||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
// Transform
|
||||
// 2015-08-13-blog-post-name-0.5.md
|
||||
// into
|
||||
// 2015/08/13/blog-post-name-0-5.html
|
||||
const filePath = path
|
||||
.basename(file)
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace(/\.md$/, '.html');
|
||||
const result = metadataUtils.extractMetadata(
|
||||
fs.readFileSync(file, {encoding: 'utf8'})
|
||||
);
|
||||
const rawContent = result.rawContent;
|
||||
const metadata = Object.assign(
|
||||
{path: filePath, content: rawContent},
|
||||
result.metadata
|
||||
);
|
||||
|
||||
metadata.id = metadata.title;
|
||||
|
||||
const metadata = blog.getMetadata(file);
|
||||
// Extract, YYYY, MM, DD from the file name
|
||||
const filePathDateArr = path
|
||||
.basename(file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue