@bbc/morty-docs 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,13 +8,13 @@ const filterFilesInDirectory = require('./helpers/filter-files-in-dir');
|
|
|
8
8
|
|
|
9
9
|
const filterDirectoriesInDirectory = require('./helpers/filter-dirs-in-dir');
|
|
10
10
|
|
|
11
|
-
const generateIndex = (directory,
|
|
11
|
+
const generateIndex = (directory, filePaths, subDirPaths, options) => {
|
|
12
12
|
const subDirLinks = subDirPaths.filter(dirPath => !dirPath.includes('/')).map(dirPath => ({
|
|
13
13
|
link: `${dirPath}/index.html`,
|
|
14
14
|
text: dirPath,
|
|
15
15
|
iconClass: 'fas fa-folder-open'
|
|
16
16
|
}));
|
|
17
|
-
const fileLinks =
|
|
17
|
+
const fileLinks = filePaths.map(filePath => {
|
|
18
18
|
const text = path.basename(filePath);
|
|
19
19
|
return {
|
|
20
20
|
link: encodeURIComponent(text),
|
|
@@ -28,8 +28,8 @@ const generateIndex = (directory, htmlFilePaths, subDirPaths, options) => {
|
|
|
28
28
|
const generateIndexes = (files, options = {
|
|
29
29
|
contentTitle: ''
|
|
30
30
|
}) => {
|
|
31
|
-
const
|
|
32
|
-
const directories = getDirectories(
|
|
31
|
+
const supportedFilePaths = files.map(file => file.relativePath).filter(relativePath => path.extname(relativePath) === '.html' || path.extname(relativePath) === '.pdf');
|
|
32
|
+
const directories = getDirectories(supportedFilePaths); // If we have not got a 'root' folder, then add one.
|
|
33
33
|
// TODO: Refactor this so it is not needed (maybe?)
|
|
34
34
|
|
|
35
35
|
if (!directories.includes('')) {
|
|
@@ -37,7 +37,7 @@ const generateIndexes = (files, options = {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const indexes = directories.map(directory => {
|
|
40
|
-
const filesInDir = filterFilesInDirectory(
|
|
40
|
+
const filesInDir = filterFilesInDirectory(supportedFilePaths, directory);
|
|
41
41
|
const subDirsInDir = filterDirectoriesInDirectory(directories, directory);
|
|
42
42
|
const indexPath = directory ? `${directory}/index.html` : 'index.html';
|
|
43
43
|
return {
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const {
|
|
2
|
+
sortArrayByDate
|
|
3
|
+
} = require('../../src/helpers/sort-array-by-date');
|
|
4
|
+
|
|
1
5
|
const filterDirs = (directoryPaths, directory) => {
|
|
2
6
|
const directoryArray = [];
|
|
3
7
|
const nestedDirFolders = directoryPaths.filter(directoryPath => directoryPath.includes(directory) && !directoryPath.startsWith(directory) && directoryPath !== directory);
|
|
@@ -6,8 +10,15 @@ const filterDirs = (directoryPaths, directory) => {
|
|
|
6
10
|
const rootDirFolders = directoryPaths.filter(directoryPath => directoryPath.startsWith(directory) && directoryPath !== directory);
|
|
7
11
|
const rootDir = rootDirFolders.map(directoryPath => directoryPath.startsWith(`${directory}/`) && directory !== '' ? directoryPath.replace(`${directory}/`, '') : directoryPath);
|
|
8
12
|
if (rootDir.length) directoryArray.push(rootDir); // if directory path starts with the config folder then remove the directory from the path
|
|
13
|
+
// sort array here
|
|
14
|
+
|
|
15
|
+
let sortedDirectoryArray = directoryArray;
|
|
16
|
+
|
|
17
|
+
if (sortedDirectoryArray.length) {
|
|
18
|
+
sortedDirectoryArray.map(arr => sortArrayByDate(arr));
|
|
19
|
+
}
|
|
9
20
|
|
|
10
|
-
return
|
|
21
|
+
return sortedDirectoryArray.flat();
|
|
11
22
|
};
|
|
12
23
|
|
|
13
24
|
module.exports = filterDirs;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return a.match(dateRegex) && b.match(dateRegex) ? b.localeCompare(a) : a.localeCompare(b);
|
|
5
|
-
}
|
|
1
|
+
const {
|
|
2
|
+
sortArrayByDate
|
|
3
|
+
} = require('../../src/helpers/sort-array-by-date');
|
|
6
4
|
|
|
7
5
|
const directoryDepth = path => path.split('/').length;
|
|
8
6
|
|
|
@@ -12,5 +10,5 @@ const isIn = directory => filePath => filePath.startsWith(directory) && director
|
|
|
12
10
|
|
|
13
11
|
module.exports = (filePaths, directory) => {
|
|
14
12
|
const isInSpecifiedDirectory = directory ? isIn(directory) : isInRootDirectory;
|
|
15
|
-
return filePaths.filter(isInSpecifiedDirectory)
|
|
13
|
+
return sortArrayByDate(filePaths.filter(isInSpecifiedDirectory));
|
|
16
14
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const dateRegex = /\d{4}-\d{2}-\d{2}/; // i.e. 2019-10-29
|
|
2
|
+
|
|
3
|
+
function sortByDate(a, b) {
|
|
4
|
+
return a.match(dateRegex) && b.match(dateRegex) ? b.localeCompare(a) : a.localeCompare(b);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const sortArrayByDate = arr => {
|
|
8
|
+
return arr.sort(sortByDate);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
sortArrayByDate
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbc/morty-docs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "To generate a static website from markdown documentation, to allow users to consume content in an easily accessible format",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"coverage": "jest --coverage --runInBand && open coverage/lcov-report/index.html",
|
|
17
17
|
"lint": "standard",
|
|
18
18
|
"prepare": "npm run build",
|
|
19
|
-
"postversion": "git push origin
|
|
19
|
+
"postversion": "git push origin main && git push --tags origin main"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"build/"
|