@bbc/morty-docs 1.7.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.
@@ -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 directoryArray.flat();
21
+ return sortedDirectoryArray.flat();
11
22
  };
12
23
 
13
24
  module.exports = filterDirs;
@@ -1,8 +1,6 @@
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
- }
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).sort(sortByDate);
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.7.0",
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 master && git push --tags origin master"
19
+ "postversion": "git push origin main && git push --tags origin main"
20
20
  },
21
21
  "files": [
22
22
  "build/"