diff --git a/app/core/contents.js b/app/core/contents.js index 8bff5b40..88017b64 100644 --- a/app/core/contents.js +++ b/app/core/contents.js @@ -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'); @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/app/core/page.js b/app/core/page.js index f4dccbc5..05c6cc3a 100644 --- a/app/core/page.js +++ b/app/core/page.js @@ -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 @@ -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 { diff --git a/app/core/search.js b/app/core/search.js index 29e46a80..80315a0a 100644 --- a/app/core/search.js +++ b/app/core/search.js @@ -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'); @@ -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; @@ -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); @@ -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; @@ -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'), - '$1' + '$1', ); return page; diff --git a/app/functions/build_nested_pages.js b/app/functions/build_nested_pages.js index ee7867bc..d2eb1605 100644 --- a/app/functions/build_nested_pages.js +++ b/app/functions/build_nested_pages.js @@ -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('/'), ); } diff --git a/app/functions/contentProcessors.js b/app/functions/contentProcessors.js index d066ac6a..9f5661a6 100644 --- a/app/functions/contentProcessors.js +++ b/app/functions/contentProcessors.js @@ -100,7 +100,7 @@ function processVars(markdownContent, config) { config.variables.forEach((v) => { markdownContent = markdownContent.replace( new RegExp(`%${v.name}%`, 'g'), - v.content + v.content, ); }); } diff --git a/app/functions/sanitize_markdown.js b/app/functions/sanitize_markdown.js index 35805178..e522b301 100644 --- a/app/functions/sanitize_markdown.js +++ b/app/functions/sanitize_markdown.js @@ -1,4 +1,3 @@ - // Modules // var validator = require('validator'); @@ -19,9 +18,7 @@ // TODO: Add Test function sanitize_markdown(str) { - return str - .replace(/ res.json()) .then((res) => { @@ -115,8 +115,8 @@ function router(config) { } else { cb(null, parsedProfile); } - } - ) + }, + ), ); passport.serializeUser((user, cb) => { @@ -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', ); } @@ -161,7 +161,7 @@ function router(config) { passport.authenticate('google', { scope: scopes, hostedDomain: config.oauth2.hostedDomain || '', - }) + }), ); // [END authorize] @@ -183,7 +183,7 @@ function router(config) { var redirect = req.session.oauth2return || '/'; delete req.session.oauth2return; res.redirect(redirect); - } + }, ); // [END callback] diff --git a/app/routes/home.route.js b/app/routes/home.route.js index f7c7ed5d..96e18f1f 100644 --- a/app/routes/home.route.js +++ b/app/routes/home.route.js @@ -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', { @@ -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: diff --git a/app/routes/page.edit.route.js b/app/routes/page.edit.route.js index 6ccc2fd0..a752bb7d 100644 --- a/app/routes/page.edit.route.js +++ b/app/routes/page.edit.route.js @@ -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; } diff --git a/app/routes/search.route.js b/app/routes/search.route.js index b5c1f6fa..a80b2304 100644 --- a/app/routes/search.route.js +++ b/app/routes/search.route.js @@ -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 diff --git a/app/routes/sitemap.route.js b/app/routes/sitemap.route.js index a8158fd3..83adeb6f 100644 --- a/app/routes/sitemap.route.js +++ b/app/routes/sitemap.route.js @@ -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 @@ -44,7 +44,7 @@ function route_sitemap(config) { lastmod: await utils.getLastModified( conf, contentProcessors.processMeta(content), - files[i] + files[i], ), }); } @@ -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 diff --git a/app/routes/wildcard.route.js b/app/routes/wildcard.route.js index f34eadf2..b52d937a 100644 --- a/app/routes/wildcard.route.js +++ b/app/routes/wildcard.route.js @@ -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 @@ -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 = diff --git a/bin/raneto b/bin/raneto index 7608c2d3..bf355051 100755 --- a/bin/raneto +++ b/bin/raneto @@ -59,7 +59,7 @@ program console.log('Raneto Service Started.'); } pm2.disconnect(); - } + }, ); }); }); @@ -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'); } diff --git a/config/config.js b/config/config.js index 63f7d8aa..a948360f 100644 --- a/config/config.js +++ b/config/config.js @@ -13,7 +13,7 @@ var theme_dir = path.join( __dirname, '..', 'node_modules', - '@raneto/theme-default' + '@raneto/theme-default', ); var theme_name = 'dist'; diff --git a/test/functions.test.js b/test/functions.test.js index 1009b4ff..8d766b99 100644 --- a/test/functions.test.js +++ b/test/functions.test.js @@ -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'); }); @@ -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); }); diff --git a/test/raneto-core.test.js b/test/raneto-core.test.js index 3bc5f535..2ba67520 100644 --- a/test/raneto-core.test.js +++ b/test/raneto-core.test.js @@ -76,7 +76,7 @@ describe('#processMeta()', () => { 'Description: This is a description\n' + 'Sort: 4\n' + 'Multi word: Value\n' + - '*/\n' + '*/\n', ); expect(result).to.have.property('title', 'This is a title'); expect(result).to.have.property('description', 'This is a description'); @@ -93,7 +93,7 @@ describe('#processMeta()', () => { it('returns proper meta from file starting with a BOM character', async () => { const result = await pageHandler( path.join(config.content_dir, 'page-with-bom.md'), - config + config, ); expect(result).to.have.property('title', 'Example Page With BOM'); }); @@ -105,7 +105,7 @@ describe('#processMeta()', () => { 'Description: This is a description\n' + 'Sort: 4\n' + 'Multi word: Value\n' + - '---\n' + '---\n', ); expect(result).to.have.property('title', 'This is a title'); expect(result).to.have.property('description', 'This is a description'); @@ -116,7 +116,7 @@ describe('#processMeta()', () => { it('returns proper meta from file starting with a BOM character (YAML)', async () => { const result = await pageHandler( path.join(config.content_dir, 'page-with-bom-yaml.md'), - config + config, ); expect(result).to.have.property('title', 'Example Page With BOM for YAML'); }); @@ -131,7 +131,7 @@ describe('#stripMeta()', () => { 'Description: This is a description\n' + 'Sort: 4\n' + 'Multi word: Value\n' + - '*/\nThis is the content' + '*/\nThis is the content', ); result.should.equal('This is the content'); }); @@ -141,7 +141,7 @@ describe('#stripMeta()', () => { '---\n' + 'Title: + This is a title\n' + '---\n' + - 'This is the content\n---' + 'This is the content\n---', ); result.should.equal('This is the content\n---'); }); @@ -166,10 +166,10 @@ describe('#stripMeta()', () => { 'Multi word: Value\n' + '*/\nThis is the content/*\n' + 'Title: This is a title\n' + - '*/' + '*/', ); result.should.equal( - 'This is the content/*\n' + 'Title: This is a title\n' + '*/' + 'This is the content/*\n' + 'Title: This is a title\n' + '*/', ); }); }); @@ -201,7 +201,7 @@ describe('#getPage()', () => { it('returns an array of values for a given page', async () => { const result = await pageHandler( path.join(config.content_dir, 'example-page.md'), - config + config, ); expect(result).to.have.property('slug', 'example-page'); expect(result).to.have.property('title', 'Example Page'); @@ -212,7 +212,7 @@ describe('#getPage()', () => { it('returns null if no page found', async () => { const result = await pageHandler( path.join(config.content_dir, 'nonexistent-page.md'), - config + config, ); /* eslint-disable no-unused-expressions */ expect(result).to.be.null; @@ -223,7 +223,10 @@ describe('#getPages()', () => { it('returns an array of categories and pages', async () => { const result = await contentsHandler(null, config); expect(result[0]).to.have.property('is_index', true); - expect(result[0].files[0]).to.have.property('title', 'Special Characters Page'); + expect(result[0].files[0]).to.have.property( + 'title', + 'Special Characters Page', + ); expect(result[1]).to.have.property('slug', 'sub'); expect(result[1].files[0]).to.have.property('title', 'Example Sub Page'); }); @@ -261,7 +264,7 @@ describe('#getPages()', () => { null, Object.assign(config, { show_on_home_default: false, - }) + }), ); expect(result[1]).to.have.property('show_on_home', false); }); @@ -271,7 +274,7 @@ describe('#getPages()', () => { null, Object.assign(config, { show_on_home_default: false, - }) + }), ); expect(result[1].files[0]).to.have.property('show_on_home', false); }); @@ -281,7 +284,7 @@ describe('#getPages()', () => { null, Object.assign(config, { show_on_home_default: false, - }) + }), ); expect(result[0]).to.have.property('show_on_home', true); }); @@ -311,7 +314,7 @@ describe('#getPages()', () => { null, Object.assign(config, { show_on_menu_default: false, - }) + }), ); expect(result[1]).to.have.property('show_on_menu', false); }); @@ -321,7 +324,7 @@ describe('#getPages()', () => { null, Object.assign(config, { show_on_menu_default: false, - }) + }), ); expect(result[1].files[0]).to.have.property('show_on_menu', false); }); @@ -331,13 +334,12 @@ describe('#getPages()', () => { null, Object.assign(config, { show_on_menu_default: false, - }) + }), ); expect(result[0]).to.have.property('show_on_menu', true); }); }); - describe('#doSearch()', () => { it('returns an array of search results', async () => { const result = await searchHandler('example', config);