@bbc/morty-docs 1.6.2 → 1.8.1

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.
package/README.md CHANGED
@@ -88,17 +88,12 @@ through because it is not markdown or asciidoc e.g. images
88
88
 
89
89
  ## Things to Consider
90
90
 
91
- ### File Ordering
91
+ ### File & Directory Ordering
92
92
 
93
- File names are sorted lexically (0-9 < a-z>), meaning that files prefixed with dates will appear at the top of the list.
93
+ These are sorted lexically (0-9 < a-z>).
94
94
 
95
- If you want your documents to be sorted reverse chronologically, use the date as a prefix to the file name in the format of YYYY-MM-DD - (19-11-2019-some-document).
96
-
97
- ## Releasing
98
-
99
- Releases are versioned through `npm version`, and publishing is handled by our [Travis CI Integration](./.travis.yml)
100
-
101
- `$ npm version (major|minor|patch)`
95
+ There is an additional sort.
96
+ If you want your documents to be sorted reverse chronologically, use the date as a prefix to the file name in the format YYYY-MM-DD e.g. `19-11-2019-some-document`. These will then be placed first above the regular sort.
102
97
 
103
98
  ## Example Architecture
104
99
 
@@ -134,6 +129,29 @@ We welcome contributions from everyone.
134
129
 
135
130
  Please respect each other.
136
131
 
132
+ ## How to contribute
133
+
134
+ Steps:
135
+
136
+ - fork the repo
137
+ - implement your fix or feature - with test coverage :-)
138
+ - raise a [PR](https://github.com/bbc/morty-docs/pulls)
139
+ - this repo now uses github actions for automated Pull Request checking & Publishing
140
+ - n.b. first-time contributors require approval to run github actions
141
+ (so your PR checker should fail to run initially)
142
+ - use ['Pull Request Checks' github action](https://github.com/bbc/morty-docs/actions/workflows/pull-requests.yml) to
143
+ see if the PR checker is passing
144
+
145
+ ### Maintainers only
146
+
147
+ - merge PR (or suggest changes)
148
+ - after merge
149
+ - use `npm version (major|minor|patch)`
150
+ - the tag created above causes
151
+ ['Node.js Package' github action](https://github.com/bbc/morty-docs/actions/workflows/npm-publish.yml) to run.
152
+ Wait for this to complete.
153
+ - verify the new version on [NPM](https://www.npmjs.com/package/@bbc/morty-docs)
154
+
137
155
  ### Adding an issue
138
156
 
139
157
  If you spot an issue or just want to raise one please use the issue template.
@@ -171,4 +189,4 @@ We would expect code quality to be at least as good if not better than
171
189
  the code quality of the project at the time you make your contribution.
172
190
  After all, we all hope to leave things better than we find them!
173
191
 
174
- © BBC 2019
192
+ © BBC 2021
@@ -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, htmlFilePaths, subDirPaths, options) => {
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 = htmlFilePaths.map(filePath => {
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 htmlFilePaths = files.map(file => file.relativePath).filter(relativePath => path.extname(relativePath) === '.html');
32
- const directories = getDirectories(htmlFilePaths); // If we have not got a 'root' folder, then add one.
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(htmlFilePaths, directory);
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 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.6.2",
3
+ "version": "1.8.1",
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/"