Skip to content

Commit

Permalink
Edit: Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlelek committed Feb 21, 2024
1 parent 6eebb5d commit 852c928
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 65 deletions.
14 changes: 7 additions & 7 deletions app/core/contents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const fs = require('fs-extra');
const { glob } = require('glob')
const { glob } = require('glob');
const _ = require('underscore');
const _s = require('underscore.string');
const yaml = require('js-yaml');
Expand Down Expand Up @@ -29,8 +29,8 @@ async function handler(activePageSlug, config) {

const results = await Promise.all(
files.map((filePath) =>
processFile(config, activePageSlug, contentDir, filePath)
)
processFile(config, activePageSlug, contentDir, filePath),
),
);

for (const result of results) {
Expand Down Expand Up @@ -70,7 +70,7 @@ async function processFile(config, activePageSlug, contentDir, filePath) {

const ignoreExists = await fs.lstat(ignoreFile).then(
(stat) => stat.isFile(),
() => {}
() => {},
);
if (ignoreExists) {
if (config.debug) {
Expand All @@ -83,10 +83,10 @@ async function processFile(config, activePageSlug, contentDir, filePath) {
let dirMetadata = {};
try {
const metaFile = await fs.readFile(
path.join(contentDir, shortPath, 'meta')
path.join(contentDir, shortPath, 'meta'),
);
dirMetadata = contentProcessors.cleanObjectStrings(
yaml.load(metaFile.toString('utf-8'))
yaml.load(metaFile.toString('utf-8')),
);
} catch (e) {
if (config.debug) {
Expand All @@ -97,7 +97,7 @@ async function processFile(config, activePageSlug, contentDir, filePath) {
if (category_sort && !dirMetadata.sort) {
try {
const sortFile = await fs.readFile(
path.join(contentDir, shortPath, 'sort')
path.join(contentDir, shortPath, 'sort'),
);
sort = parseInt(sortFile.toString('utf-8'), 10);
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions app/core/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function handler(filePath, config) {
const meta = contentProcessors.processMeta(file.toString('utf-8'));
const content = contentProcessors.processVars(
contentProcessors.stripMeta(file.toString('utf-8')),
config
config,
);

// Render Markdown
Expand All @@ -34,7 +34,7 @@ async function handler(filePath, config) {
const title = meta.title ? meta.title : contentProcessors.slugToTitle(slug);
const excerpt = _s.prune(
_s.stripTags(_s.unescapeHTML(body)),
config.excerpt_length || 400
config.excerpt_length || 400,
);

return {
Expand Down
14 changes: 7 additions & 7 deletions app/core/search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
const { glob } = require('glob')
const { glob } = require('glob');
const contentProcessors = require('../functions/contentProcessors');
const utils = require('./utils');
const pageHandler = require('./page');
Expand All @@ -14,7 +14,7 @@ function getLunr(config) {
require('lunr-languages/lunr.multi')(instance);
require('lunr-languages/tinyseg')(instance);
config.searchExtraLanguages.forEach((lang) =>
require(`lunr-languages/lunr.${lang}`)(instance)
require(`lunr-languages/lunr.${lang}`)(instance),
);
}
return instance;
Expand All @@ -33,8 +33,8 @@ async function handler(query, config) {
const rawDocuments = await glob(`${contentDir}**/*.md`);
const potentialDocuments = await Promise.all(
rawDocuments.map((filePath) =>
contentProcessors.extractDocument(contentDir, filePath, config.debug)
)
contentProcessors.extractDocument(contentDir, filePath, config.debug),
),
);
const documents = potentialDocuments.filter((doc) => doc !== null);

Expand All @@ -51,8 +51,8 @@ async function handler(query, config) {

const searchResults = await Promise.all(
results.map((result) =>
processSearchResult(contentDir, config, query, result)
)
processSearchResult(contentDir, config, query, result),
),
);

return searchResults;
Expand All @@ -62,7 +62,7 @@ async function processSearchResult(contentDir, config, query, result) {
const page = await pageHandler(contentDir + result.ref, config);
page.excerpt = page.excerpt.replace(
new RegExp(`(${query})`, 'gim'),
'<span class="search-query">$1</span>'
'<span class="search-query">$1</span>',
);

return page;
Expand Down
2 changes: 1 addition & 1 deletion app/functions/build_nested_pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function build_nested_pages(pages) {

function find_by_slug(pages, page) {
return pages.find(
(element) => element.slug === page.slug.split('/').slice(0, -1).join('/')
(element) => element.slug === page.slug.split('/').slice(0, -1).join('/'),
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/functions/contentProcessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function processVars(markdownContent, config) {
config.variables.forEach((v) => {
markdownContent = markdownContent.replace(
new RegExp(`%${v.name}%`, 'g'),
v.content
v.content,
);
});
}
Expand Down
5 changes: 1 addition & 4 deletions app/functions/sanitize_markdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Modules
// var validator = require('validator');

Expand All @@ -19,9 +18,7 @@

// TODO: Add Test
function sanitize_markdown(str) {
return str
.replace(/</g, '&lt;')
.replace(/(\s)&(\s)/g, ' &amp; ');
return str.replace(/</g, '&lt;').replace(/(\s)&(\s)/g, ' &amp; ');
}

// Exports
Expand Down
16 changes: 8 additions & 8 deletions app/middleware/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ function authRequired(req, res, next) {
function addTemplateVariables(req, res, next) {
res.locals.profile = req.user;
res.locals.login = `/auth/login?return=${encodeURIComponent(
req.originalUrl
req.originalUrl,
)}`;
res.locals.logout = `/auth/logout?return=${encodeURIComponent(
req.originalUrl
req.originalUrl,
)}`;
next();
}
Expand Down Expand Up @@ -102,7 +102,7 @@ function router(config) {
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
},
)
.then((res) => res.json())
.then((res) => {
Expand All @@ -115,8 +115,8 @@ function router(config) {
} else {
cb(null, parsedProfile);
}
}
)
},
),
);

passport.serializeUser((user, cb) => {
Expand All @@ -134,7 +134,7 @@ function router(config) {
if (config.google_group_restriction.enabled) {
scopes.push(
'https://www.googleapis.com/auth/admin.directory.group.readonly',
'https://www.googleapis.com/auth/admin.directory.user.readonly'
'https://www.googleapis.com/auth/admin.directory.user.readonly',
);
}

Expand All @@ -161,7 +161,7 @@ function router(config) {
passport.authenticate('google', {
scope: scopes,
hostedDomain: config.oauth2.hostedDomain || '',
})
}),
);
// [END authorize]

Expand All @@ -183,7 +183,7 @@ function router(config) {
var redirect = req.session.oauth2return || '/';
delete req.session.oauth2return;
res.redirect(redirect);
}
},
);
// [END callback]

Expand Down
4 changes: 2 additions & 2 deletions app/routes/home.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function route_home(config) {
page.files = _.filter(page.files, (file) => file.show_on_home);
return page;
})
.value()
.value(),
);

return res.render('home', {
Expand All @@ -56,7 +56,7 @@ function route_home(config) {
last_modified: await utils.getLastModified(
config,
config.home_meta,
template_filepath
template_filepath,
),
lang: config.lang,
loggedIn:
Expand Down
2 changes: 1 addition & 1 deletion app/routes/page.edit.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function route_page_edit(config) {
var meta = create_meta_info(
body.meta_title,
body.meta_description,
body.meta_sort
body.meta_sort,
);
return meta + body.content;
}
Expand Down
2 changes: 1 addition & 1 deletion app/routes/search.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function route_search(config) {
searchResults = await searchHandler(sanitizedQuery, config);
pageListSearch = remove_image_content_directory(
config,
await contentsHandler(null, config)
await contentsHandler(null, config),
);
} catch (e) {
// Continue with defaults of empty arrays
Expand Down
6 changes: 3 additions & 3 deletions app/routes/sitemap.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function route_sitemap(config) {

// generate list urls
var urls = filesPath.map(
(file) => `/${file.replace('.md', '').replace('\\', '/')}`
(file) => `/${file.replace('.md', '').replace('\\', '/')}`,
);

// create sitemap.xml
Expand All @@ -44,7 +44,7 @@ function route_sitemap(config) {
lastmod: await utils.getLastModified(
conf,
contentProcessors.processMeta(content),
files[i]
files[i],
),
});
}
Expand All @@ -66,7 +66,7 @@ async function listFiles(dir) {
const filePath = path.join(dir, entry);
const isDir = (await fs.stat(filePath)).isDirectory();
return isDir ? listFiles(filePath) : [filePath];
})
}),
);

// Return the flattened array
Expand Down
7 changes: 3 additions & 4 deletions app/routes/wildcard.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function route_wildcard(config) {
if (
file_path_orig.indexOf(
suffix,
file_path_orig.length - suffix.length
file_path_orig.length - suffix.length,
) !== -1
) {
// Edit Page
Expand Down Expand Up @@ -105,12 +105,11 @@ function route_wildcard(config) {
.filter((page) => page.show_on_menu)
.map((page) => {
page.files = _.filter(page.files, (file) => {
return file.show_on_menu
return file.show_on_menu;
});
return page;
})
.value()

.value(),
);

var loggedIn =
Expand Down
4 changes: 2 additions & 2 deletions bin/raneto
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ program
console.log('Raneto Service Started.');
}
pm2.disconnect();
}
},
);
});
});
Expand Down Expand Up @@ -144,7 +144,7 @@ program
function customHelp(text) {
var textArray = text.split(/\r?\n/);
textArray[3] = ` Config: ${path.normalize(
path.join(__dirname, '..', 'example', 'config.default.js')
path.join(__dirname, '..', 'example', 'config.default.js'),
)}\n`;
return textArray.join('\n');
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var theme_dir = path.join(
__dirname,
'..',
'node_modules',
'@raneto/theme-default'
'@raneto/theme-default',
);
var theme_name = 'dist';

Expand Down
6 changes: 3 additions & 3 deletions test/functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('#get_last_modified()', () => {
const modified = await utils.getLastModified(
config,
contentProcessors.processMeta(content),
file_path
file_path,
);
expect(modified).to.be.equal('14th Sep 2016');
});
Expand All @@ -45,10 +45,10 @@ describe('#get_last_modified()', () => {
const modified = await utils.getLastModified(
config,
contentProcessors.processMeta(content),
file_path
file_path,
);
const fstime = moment(fs.lstatSync(file_path).mtime).format(
config.datetime_format
config.datetime_format,
);
expect(modified).to.be.equal(fstime);
});
Expand Down
Loading

0 comments on commit 852c928

Please sign in to comment.