Skip to content

Documentation amended to be available in printable format #2830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ npm-debug.log
yarn-error.log
package-lock.json
.cache
internal-links.tap
internal-links.tap
src/content/**/*_all.md
78 changes: 78 additions & 0 deletions concatenate-docs.js
Original file line number Diff line number Diff line change
@@ -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"); });
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"linkcheck": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ --skip support__ --skip sidecar.gitter.im --skip vimdoc.sourceforge.net --skip img.shields.io --skip npmjs.com/package/ --skip opencollective.com/webpack --todo external-redirect | tee external-links.tap | tap-spot",
"sitemap": "cd dist && sitemap-static --prefix=https://webpack.js.org/ > sitemap.xml",
"serve": "npm run build && sirv start ./dist --port 4000",
"deploy": "gh-pages -d dist"
"deploy": "gh-pages -d dist",
"chapterize": "node ./concatenate-docs.js"
},
"husky": {
"hooks": {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Gitter/Gitter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
@import 'functions';

.gitter {
@media print {
display: none !important;
}

position: absolute;
right: 1.5em;
height: calc(100% - 1.5em);
Expand Down
4 changes: 4 additions & 0 deletions src/components/NotificationBar/NotificationBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
@import 'mixins';

.notification-bar {
@media print {
display: none !important;
}

color: getColor(white);
background: getColor(emperor);

Expand Down
2 changes: 1 addition & 1 deletion src/components/Page/Page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Page extends React.Component {
)}

{loadContributors && (
<div>
<div className="contributors__section">
<hr />
<h3>Contributors</h3>
<Contributors contributors={contributors} />
Expand Down
7 changes: 7 additions & 0 deletions src/components/Page/Page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@
padding: 1.5em;
}
}

.contributors__section
{
@media print {
display: none !important;
}
}
4 changes: 4 additions & 0 deletions src/components/PageLinks/PageLinks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
@import 'functions';

.page-links {
@media print {
display: none !important;
}

position: absolute;
display: none;
top: 1.5em;
Expand Down
9 changes: 9 additions & 0 deletions src/components/Site/Site.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
@media print {

header,
nav,
footer {
display: none !important;
}
}

.site {
display: flex;
flex-direction: column;
Expand Down