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:
Endilie Yacop Sucipto 2018-07-24 13:37:52 +07:00 committed by GitHub
parent bbfb4b09cb
commit afec4bd47c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 249 additions and 214 deletions

View file

@ -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)