Skip to content
Open
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
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["env", "react"],
"plugins": ["transform-react-jsx"]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
node_modules
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

> Useful posts, articles, videos and podcasts related to development

## How to use

### Latest links
Browse the directories for a summary and link to each article.

- [Optimising React Apps in Production](https://github.com/times/learning/blob/master/react/optimising-react-apps-in.md) _submitted by [@elliotdavies](https://github.com/elliotdavies)_
- [CS50 Introduction to Computer Science](https://github.com/times/learning/blob/master/general/cs50.md) _submitted by [@mattietk](https://github.com/MattieTK)_
- [What does Lambda support?](https://github.com/times/learning/blob/master/aws/what-does-lambda-support.md) _submitted by [@chrishutchinson](https://github.com/chrishutchinson)_
## Contributing

Just create a PR adding the markdown file with the appropriate information. Fill
in a copy of the `template.md` file and place it in the appropriate directory
(create a new directory if necessary). See the `CONTRIBUTING.md` file for
contribution guidelines.

### How to use
## To build the `index.html` page

Browse the directories for a summary and link to each article.
1. Install the dependencies

```
$ yarn
```

### Contributing
2. Run the `index.js` Node.js script using the following command:

Just create a PR adding the markdown file with the appropriate information. Fill in a copy of the `template.md` file and place it in the appropriate directory (create a new directory if necessary). See the `CONTRIBUTING.md` file for contribution guidelines.
```
$ yarn build
```
84 changes: 84 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const React = require("react");
const ReactMarkdown = require("react-markdown");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we've discussed as a team what our default prettier settings should be – the EB version (i.e. single quotes, trailing commas) or the tool defaults? Either way we should maybe add a .pretterrc to this repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I totally meant to add one - I'll do that


const capitalise = string => {
if (string === "aws") return string.toUpperCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of future-proofing, this could be an array of names?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good shout, will do


return `${string.charAt(0).toUpperCase()}${string.slice(1)}`;
};

const Sidebar = ({ files, latest }) => (
<aside className="sticky">
<a href="#">
<img src="./dual-masthead.svg" />
</a>
<ul className="categories">
{Object.keys(files).map((folder, index) => {
const documents = files[folder];
if (documents.length === 0) return null;

return (
<li key={index}>
<a href={`#${folder}`}>{folder}</a>
</li>
);
})}
</ul>

<div className="latestWrapper">
<h2>Latest additions</h2>
<ul className="latest">
{latest.map((f, index) => (
<li key={index}>
<a href={`#${f.name}`}>{f.headline}</a>
</li>
))}
</ul>
</div>
</aside>
);

const Content = ({ files }) => (
<main>
<header>
<a
className="github-button"
href="https://github.com/times/learning"
data-icon="octicon-star"
data-size="large"
data-show-count="true"
aria-label="Star times/learning on GitHub"
>
Star
</a>

<h1>🎓 Learning</h1>
<p>Useful posts, articles, videos and podcasts related to development</p>
</header>

{Object.keys(files).map((folder, index) => {
const documents = files[folder];
if (documents.length === 0) return null;

return (
<section key={index} id={folder}>
<h2>{capitalise(folder)}</h2>
{documents.map(({ name, content }, index) => (
<div className="markdown" key={index} id={name}>
<ReactMarkdown source={content} />
</div>
))}
</section>
);
})}
</main>
);

const App = ({ files, latest }) => (
<div className="wrapper">
<Sidebar files={files} latest={latest} />
<Content files={files} />
</div>
);

module.exports = App;
118 changes: 118 additions & 0 deletions dual-masthead.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions index.html

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const fs = require("fs");
const React = require("react");
const ReactDOMServer = require("react-dom/server");

const App = require("./app");

const getDirectories = (path, ignore = []) =>
fs
.readdirSync(path)
.filter(a => fs.statSync(`${path}${a}`).isDirectory())
.filter(a => !ignore.includes(a));

const getFiles = (path, extension, ignore = []) =>
fs
.readdirSync(path)
.filter(a => fs.statSync(`${path}${a}`).isFile())
.filter(a => a.endsWith(extension))
.filter(a => !ignore.includes(a))
.map(a => {
const content = fs.readFileSync(`${path}${a}`).toString();
return {
name: a,
content,
headline: content.match(/# \[(.*?)\]/)[1],
dateAdded: fs.statSync(`${path}${a}`).birthtime

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

birthtime 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed the most appropriate from this list

};
});

const directories = getDirectories("./", [".git", "node_modules"]);

const markdownFiles = directories.reduce(
(acc, s) =>
Object.assign({}, acc, {
[s]: getFiles(`./${s}/`, ".md")
}),
{}
);

const latestFiles = directories
.reduce((acc, s) => [...acc, ...getFiles(`./${s}/`, ".md")], [])
.sort((a, b) => {
const diff = a.dateAdded - b.dateAdded;
if (diff === 0) return diff;
return diff > 0 ? -1 : 1;
})
.splice(0, 3);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, honestly, but technically splice is a mutation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, I think I meant slice


const html = ReactDOMServer.renderToStaticMarkup(
<App files={markdownFiles} latest={latestFiles} />
);

fs.writeFileSync(
"./index.html",
`<html>
<head>
<title>Learning!</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="./style.css" />
<link rel="stylesheet" href="https://fonts.timesdev.tools/fonts/TimesModern-Bold.css" />
<link rel="stylesheet" href="https://fonts.timesdev.tools/fonts/TimesModern-Regular.css" />
</head>
<body>
${html}

<script async defer src="https://buttons.github.io/buttons.js"></script>
<script src="node_modules/stickyfilljs/dist/stickyfill.min.js"></script>
<script type="text/javascript">
Stickyfill.add(document.querySelectorAll('.sticky'));
</script>
</body>
</html>`
);

process.exit();
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "learning",
"version": "1.0.0",
"description":
"Useful posts, articles, videos and podcasts related to development",
"main": "index.js",
"repository": "git@github.com:times/learning.git",
"author": "Chris Hutchinson <chris.hutchinson@thetimes.co.uk>",
"license": "MIT",
"private": false,
"scripts": {
"build": "./node_modules/babel-cli/bin/babel-node.js index.js"
},
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-markdown": "^3.0.1",
"stickyfilljs": "^2.0.3"
}
}
Loading