diff --git a/.gitignore b/.gitignore index cbdc7c1002d9..7a30f590d9a6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ starter-kits-data.json .DS_Store yarn-error.log package-lock.json +src/content/**/*_all.md \ No newline at end of file diff --git a/concatenate-docs.js b/concatenate-docs.js new file mode 100644 index 000000000000..5d2a7c48ec0f --- /dev/null +++ b/concatenate-docs.js @@ -0,0 +1,78 @@ +// start message +console.info("\x1b[0m\x1b[36mConcatenating help files of each directory to create chapter-wide help files to be used for printing help ...\x1b[0m"); + +// ------ various includes ------ +const fs = require("fs"); +const path = require("path"); +const os = require("os"); +const front = require("front-matter"); + +// root path +const rootPath = path.join("src", "content"); + +/* getDirectoryRecursive() recursively walks through + all sub directories of the provided root path, + concatenates the MarkDown files' content in + each directory, sorted by their FrontMatter sort + attribute, and creates a compound MarkDown file + named by using the directory name, prefixed by an + underscore and suffixed by "_all.md" from the + concatenated content in the corresponding directory. +*/ +(function getDirectoryRecursive(basePath) +{ + // log current working directory + console.log("\x1b[0m\x1b[32m " + basePath + "\x1b[0m"); + + // create destination file name of compound file + const targetFilePath = path.join(basePath, `${basePath.substr(rootPath.length).replace(/[/\\]/, "_")}_all.md`); + + if (fs.existsSync(targetFilePath)) fs.unlinkSync(targetFilePath); // delete target file if it already exists + + fs.readdir(basePath, function (err, fileNames) // list current working directory + { + if (err) throw err; + + let fileContents = []; + + for (let file of fileNames) // for each directory entry ... + { + const fullPath = path.join(basePath, file); + + if (fs.statSync(fullPath).isDirectory()) getDirectoryRecursive(fullPath); // if the directory entry is a directory, recurse into that directory + else if (fullPath.endsWith(".md")) // if the directory entry is a MarkDown file, add it to the list of files to be processed + { + let fc = fileContents[fileContents.length] = front(fs.readFileSync(fullPath).toString()); + + if (!fc.attributes.sort) --fileContents.length; // only include files providing a FrontMatter "sort" attribute + } + } + + // sort MarkDown files by FrontMatter "sort" attribute (QuickSort) + for (let i = 0;i < fileContents.length - 1;++i) + for (let j = i + 1;j < fileContents.length;++j) + { + const left = fileContents[i].attributes, right = fileContents[j].attributes; + + if (left.sort > right.sort + || left.sort == right.sort && left.title > right.title) + [fileContents[i], fileContents[j]] = [fileContents[j], fileContents[i]]; + } + + // write compound target file + const targetFile = fs.createWriteStream(targetFilePath); + + targetFile.on("error", (error) => { throw error; }); + + for (let file of fileContents) + { + targetFile.write(os.EOL + os.EOL + "# " + file.attributes.title + os.EOL); // use FrontMatter "title" attribute as main heading of target file + targetFile.write(file.body); + } + + targetFile.end(); + }); +})(rootPath); + +// end message +process.on("exit", () => { console.info("\x1b[0m\x1b[36mSuccessfully created \"_all.md\" help files in each directory within \"" + rootPath + "\".\x1b[0m"); }); \ No newline at end of file diff --git a/package.json b/package.json index 96f6834bb6f5..0cc1e167f949 100644 --- a/package.json +++ b/package.json @@ -33,11 +33,12 @@ "init:generated": "mkdirp ./generated/loaders && mkdirp ./generated/plugins ", "lint": "run-s lint:*", "lint:js": "eslint . --ext .js,.jsx,.md", - "lint:markdown": "markdownlint --rules markdownlint-rule-emphasis-style --config ./.markdownlint.json *.md ./src/content/*.md ./src/content/**/*.md", + "lint:markdown": "markdownlint --rules markdownlint-rule-emphasis-style --config ./.markdownlint.json --ignore *.md ./src/content/**/*.md", "lint:social": "alex . -q", "lint:prose": "cp .proselintrc ~/ && proselint src/content", "test": "npm run lint", - "sitemap": "cd build && sitemap-static --prefix=https://webpack.js.org/ > sitemap.xml" + "sitemap": "cd build && sitemap-static --prefix=https://webpack.js.org/ > sitemap.xml", + "chapterize": "node ./concatenate-docs.js" }, "husky": { "hooks": { diff --git a/src/components/Footer/Footer.scss b/src/components/Footer/Footer.scss index 106d52ec0de3..4388e8be401c 100644 --- a/src/components/Footer/Footer.scss +++ b/src/components/Footer/Footer.scss @@ -4,6 +4,10 @@ .footer { width: 100%; flex: 0 0 auto; + + @media print { + display: none !important; + } } .footer__inner { diff --git a/src/components/Page/Page.jsx b/src/components/Page/Page.jsx index a21ce4d20156..e2b93794f766 100644 --- a/src/components/Page/Page.jsx +++ b/src/components/Page/Page.jsx @@ -81,7 +81,7 @@ const Page = ({ page, section }) => { )} { contributors.length > 0 && ( -