@bbc/morty-docs 2.0.0 → 3.0.2

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
@@ -197,4 +197,4 @@ We would expect code quality to be at least as good if not better than
197
197
  the code quality of the project at the time you make your contribution.
198
198
  After all, we all hope to leave things better than we find them!
199
199
 
200
- © BBC 2021
200
+ © BBC 2024
@@ -1,15 +1,56 @@
1
- const readdir = require('recursive-readdir');
2
1
  const fs = require('fs');
3
2
  const path = require('path');
4
3
  const generateTransformInput = dir => {
5
4
  dir = path.format(path.parse(dir));
6
- return readdir(dir).then(files => {
7
- return files.map(file => {
8
- return {
9
- relativePath: file.toString().replace(`${dir}/`, ''),
10
- raw: fs.readFileSync(file)
11
- };
12
- });
5
+ let list = [];
6
+ const files = fs.readdirSync(dir, {
7
+ recursive: true,
8
+ withFileTypes: true
13
9
  });
10
+ // recursive option available from node 18+
11
+ // when options.withFileTypes set to true, the returned array will contain <fs.Dirent> objects.
12
+ for (const dirent of files) {
13
+ // Node API for Dirent is unstable
14
+ const dirPath = dirent.path || dirent.parentPath; // path is DEPRECATED! But parentPath does not work in 18.17
15
+
16
+ const fullPath = path.join(dirPath, dirent.name);
17
+ // console.log('fullPath = ', fullPath)
18
+
19
+ if (dirent.isDirectory()) {
20
+ console.log('directory... continue');
21
+ continue;
22
+ }
23
+ if (dirent.isFile()) {
24
+ list.push(makeInputObject(fullPath, dir));
25
+ continue;
26
+ }
27
+ if (dirent.isSymbolicLink) {
28
+ if (fs.existsSync(fullPath)) {
29
+ // fs.exists() is deprecated, but fs.existsSync() is not.
30
+ const stats = fs.statSync(fullPath);
31
+ console.log('Good symlink', fullPath);
32
+ if (stats.isFile()) {
33
+ // get file details
34
+ list.push(makeInputObject(fullPath, dir)); // symlinks become copies
35
+ } else {
36
+ console.log('directory... continue');
37
+ // recursive call to get all files in the symlinked directory
38
+ const newlist = generateTransformInput(fullPath);
39
+ list = list.concat(newlist);
40
+ }
41
+ } else {
42
+ console.log(`Broken symlink at: ${fullPath}`);
43
+ }
44
+ continue;
45
+ }
46
+ }
47
+ console.log(list);
48
+ return list;
49
+ };
50
+ const makeInputObject = (fullPath, rootPath) => {
51
+ return {
52
+ relativePath: fullPath.replace(`${rootPath}/`, ''),
53
+ raw: fs.readFileSync(fullPath)
54
+ };
14
55
  };
15
56
  module.exports = generateTransformInput;
@@ -45,8 +45,14 @@ const createParser = options => {
45
45
  // exclude colon, so external links aren't converted
46
46
  replace: `<a href="${basePath}/$1">`
47
47
  };
48
+ const addBasePathToLinkHrefs = {
49
+ type: 'output',
50
+ regex: /<link(.+)href="\/([^:\n]*)"(.*)\/>/g,
51
+ // exclude colon, so external links aren't converted
52
+ replace: `<link$1href="${basePath}/$2"$3/>`
53
+ };
48
54
  const parser = new showdown.Converter({
49
- extensions: [convertMdLinksToHtmlLinks, convertMdHashLinksToHtmlLinks, addBasePathToRootLinks, headingExtension, ...bindings]
55
+ extensions: [convertMdLinksToHtmlLinks, convertMdHashLinksToHtmlLinks, addBasePathToRootLinks, addBasePathToLinkHrefs, headingExtension, ...bindings]
50
56
  });
51
57
  parser.setFlavor('github');
52
58
  return parser;
@@ -134,12 +134,12 @@ const contentStyles = `
134
134
  border-radius: 0;
135
135
  }
136
136
 
137
- .content p code {
137
+ .content :not(pre) code {
138
138
  padding: 2px 4px;
139
- font-size: 90%;
140
- color: #c7254e;
141
- background-color: #f9f2f4;
142
- border-radius: 4px;
139
+ font-size: 90%;
140
+ color: #c7254e;
141
+ background-color: #f9f2f4;
142
+ border-radius: 4px;
143
143
  }
144
144
 
145
145
  .content table {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbc/morty-docs",
3
- "version": "2.0.0",
3
+ "version": "3.0.2",
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": {
@@ -31,7 +31,8 @@
31
31
  "markdown"
32
32
  ],
33
33
  "engines": {
34
- "node": ">=12.x"
34
+ "node": ">=18.x",
35
+ "npm": ">=8.x"
35
36
  },
36
37
  "author": "BBC",
37
38
  "license": "Apache-2.0",