-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInnerPages.js
31 lines (29 loc) · 1005 Bytes
/
InnerPages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { startCase } = require('lodash');
const { dirname } = require('path');
const config = require('./../config/instance');
const glob = require('glob');
/**
* Get list of sub pages for current request (usefull with default routing)
*/
module.exports = function (folderPath) {
if (folderPath.endsWith('.html')) {
folderPath = dirname(folderPath);
if (!folderPath.endsWith('/')) {
folderPath += '/';
}
}
return glob.sync('*', {
cwd: `${config.serverViews}/pages/${folderPath}`, // Get all sub folders and HTML pages
mark: true
}).sort().map((file) => {
if (file.startsWith('_')) {
return null; // Ignore files, started with "_" (but they are available directly)
}
const isDir = file.endsWith('/');
return {
title: startCase(file.replace(/\.html$/, '')), // User friendly format
isDir: isDir,
href: isDir ? `${folderPath}${file}${config.defaultPageUrl}` : `${folderPath}${file}` // link to page
};
}).filter(Boolean);
};