Skip to content

Commit

Permalink
use includes() and add 'markup' naming for function
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Jul 23, 2018
1 parent f80cf9f commit ea03634
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
8 changes: 4 additions & 4 deletions lib/server/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function fileToUrl(file) {
.replace(/\.md$/, '.html');
}

function getPages(numOfBlog, config) {
function getPagesMarkup(numOfBlog, config) {
const BlogPageLayout = require('../core/BlogPageLayout.js');
const blogPages = {};
const perPage = 10;
Expand Down Expand Up @@ -63,7 +63,7 @@ function getMetadata(file) {
return metadata;
}

function getPost(file, config) {
function getPostMarkup(file, config) {
const metadata = getMetadata(file);
if (!metadata) {
return null;
Expand All @@ -80,7 +80,7 @@ function getPost(file, config) {
module.exports = {
fileToUrl,
getMetadata,
getPages,
getPost,
getPagesMarkup,
getPostMarkup,
urlToSource,
};
13 changes: 5 additions & 8 deletions lib/server/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function replaceAssetsLink(oldContent) {
return lines.join('\n');
}

function getStr(rawContent, mdToHtml, metadata) {
function getMarkup(rawContent, mdToHtml, metadata) {
// generate table of contents
let content = insertTOC(rawContent);

Expand All @@ -104,11 +104,8 @@ function getStr(rawContent, mdToHtml, metadata) {
);
}

function getRedirectStr(metadata) {
if (
!env.translation.enabled ||
metadata.permalink.indexOf('docs/en') === -1
) {
function getRedirectMarkup(metadata) {
if (!env.translation.enabled || !metadata.permalink.includes('docs/en')) {
return null;
}
const Redirect = require('../core/Redirect.js');
Expand All @@ -124,9 +121,9 @@ function getRedirectStr(metadata) {
}

module.exports = {
getStr,
getMarkup,
getFile,
getRedirectStr,
getRedirectMarkup,
mdToHtmlify,
replaceAssetsLink,
};
16 changes: 8 additions & 8 deletions lib/server/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ async function execute() {
return;
}
const rawContent = metadataUtils.extractMetadata(file).rawContent;
const str = docs.getStr(rawContent, mdToHtml, metadata);
const str = docs.getMarkup(rawContent, mdToHtml, metadata);
const targetFile = join(buildDir, metadata.permalink);
writeFileAndCreateFolder(targetFile, str);

// generate english page redirects when languages are enabled
const redirectStr = docs.getRedirectStr(metadata);
if (!redirectStr) {
const redirectMarkup = docs.getRedirectMarkup(metadata);
if (!redirectMarkup) {
return;
}
const redirectFile = join(
buildDir,
metadata.permalink.replace('docs/en', 'docs')
);
writeFileAndCreateFolder(redirectFile, redirectStr);
writeFileAndCreateFolder(redirectFile, redirectMarkup);
});

// copy docs assets if they exist
Expand Down Expand Up @@ -120,16 +120,16 @@ async function execute() {
return;
}
const urlPath = blog.fileToUrl(normalizedFile);
const str = blog.getPost(normalizedFile, siteConfig);
if (!str) {
const blogPost = blog.getPostMarkup(normalizedFile, siteConfig);
if (!blogPost) {
return;
}
const targetFile = join(buildDir, 'blog', urlPath);
writeFileAndCreateFolder(targetFile, str);
writeFileAndCreateFolder(targetFile, blogPost);
});

// create html files for all blog pages (collections of article previews)
const blogPages = blog.getPages(MetadataBlog.length, siteConfig);
const blogPages = blog.getPagesMarkup(MetadataBlog.length, siteConfig);
Object.keys(blogPages).forEach(pagePath => {
const targetFile = join(buildDir, 'blog', pagePath);
writeFileAndCreateFolder(targetFile, blogPages[pagePath]);
Expand Down
7 changes: 3 additions & 4 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ function execute(port, options) {
const rawContent = metadataUtils.extractMetadata(file).rawContent;
removeModuleAndChildrenFromCache('../core/DocsLayout.js');
const mdToHtml = metadataUtils.mdToHtml(Metadata, siteConfig.baseUrl);
const str = docs.getStr(rawContent, mdToHtml, metadata);
res.send(str);
res.send(docs.getMarkup(rawContent, mdToHtml, metadata));
});

app.get(routing.sitemap(siteConfig.baseUrl), (req, res) => {
Expand Down Expand Up @@ -180,7 +179,7 @@ function execute(port, options) {
// this to regenerate on file save rather than on page request.
reloadMetadataBlog();
removeModuleAndChildrenFromCache(join('..', 'core', 'BlogPageLayout.js'));
const blogPages = blog.getPages(MetadataBlog.length, siteConfig);
const blogPages = blog.getPagesMarkup(MetadataBlog.length, siteConfig);
const urlPath = req.path.toString().split('blog/')[1];

if (urlPath === 'index.html') {
Expand All @@ -192,7 +191,7 @@ function execute(port, options) {
} else {
const file = join(CWD, 'blog', blog.urlToSource(urlPath));
removeModuleAndChildrenFromCache(join('..', 'core', 'BlogPostLayout.js'));
const blogPost = blog.getPost(file, siteConfig);
const blogPost = blog.getPostMarkup(file, siteConfig);
if (!blogPost) {
next();
return;
Expand Down

0 comments on commit ea03634

Please sign in to comment.