Skip to content

Commit 1e06584

Browse files
committed
0 parents  commit 1e06584

25 files changed

+23513
-0
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2

.eslintrc.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:import/errors",
5+
"plugin:react/recommended",
6+
"plugin:jsx-a11y/recommended",
7+
"prettier",
8+
"prettier/react"
9+
],
10+
"rules": {
11+
"react/prop-types": 0,
12+
"jsx-a11y/label-has-for": 0,
13+
"no-console": 1
14+
},
15+
"plugins": ["react", "import", "jsx-a11y"],
16+
"parser": "babel-eslint",
17+
"parserOptions": {
18+
"ecmaVersion": 2018,
19+
"sourceType": "module",
20+
"ecmaFeatures": {
21+
"jsx": true
22+
}
23+
},
24+
"env": {
25+
"es6": true,
26+
"browser": true,
27+
"node": true
28+
},
29+
"settings": {
30+
"react": {
31+
"version": "16.5.2"
32+
}
33+
}
34+
}

.github/workflows/gatsby.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy Gatsby Site to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@master
13+
- name: npm install, build, and csv
14+
run: |
15+
npm install
16+
npm run build
17+
npm run csv
18+
- name: Deploy site to gh-pages branch
19+
uses: alex-page/[email protected]
20+
with:
21+
repo-token: ${{ secrets.ACCESS_TOKEN }}
22+
site-directory: public

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Project dependencies
2+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3+
node_modules
4+
.cache/
5+
# Build directory
6+
public/
7+
.DS_Store
8+
yarn-error.log

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

LICENSE

Lines changed: 161 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<h1 align="center">gatsby-course-starter</h1> <br>
2+
3+
<p align="center">
4+
A Gatsby starter to get you started creating educational materials using Markdown
5+
</p>
6+
7+
## Get Started
8+
9+
1. `npm install --global gatsby-cli` - make sure you're on Gatsby v2+
10+
- See [docs here](https://next.gatsbyjs.org/docs/) if you need help
11+
1. `gatsby new course-website https://github.com/btholt/gatsby-course-starter`
12+
1. `cd course-website`
13+
1. `npm run dev`
14+
1. Open http://localhost:8000 in your browser
15+
16+
## Lessons
17+
18+
The crux of this site is are the lessons. Provided are two examples. Each lesson needs a [frontmattter](https://github.com/gatsbyjs/gatsby/blob/master/docs/docs/adding-markdown-pages.md#note-on-creating-markdown-files) `path`, `order`, and `title`. Generally you should make the `path` and the file name match for ease of finding it.
19+
20+
- `path` - needs a leading slash. This will be slug of the lesson
21+
- `title` - will be the title displayed on the Table of Contents and on the page itself
22+
- `order` - the order of which the item should appear in the table of contents. should in `<number><capital letter>` format where the number corresponds to the section it's and the letter corresponds to the order of the lesson inside the section, e.g. `3B`
23+
- `section` - the title of the section that the article is in. Only the first lesson for each section will be used.
24+
- `description` – a one-to-three sentence summary of the lesson. used for the meta tag for social shares and SEO. if no description is given, the `siteMetadata.description` for the site is used
25+
26+
## Config
27+
28+
Inside of `gatsby-config.js` be sure to fill out the `siteMetadata` fields, including `title`, `subtitle`, `description`, and `keywords`.
29+
30+
## GitHub Pages
31+
32+
If you do want to deploy to GitHub pages, make sure you add the name of the repo to the `pathPrefix` property in `gatsby-config.js` so that it will correctly make all the links.
33+
34+
## GitHub Actions
35+
36+
This site is ready to deployed to GitHub Pages out of the box with GitHub Actions. If you do not want to deploy this to GitHub Pages, delete the `.github` directory.
37+
38+
If you do want to deploy this to GitHub Pages with GitHub Actions, you need to do a few things.
39+
40+
1. Create a [personal access token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) with rights to read and write to repos.
41+
1. Put that token in your repos secrets. Click the Settings tab and paste your access token in the Secrets tab with the key `ACCESS_TOKEN`.
42+
1. Now once you commit your code, it should automatically deploy your GitHub Pages site should deploy automatically!
43+
44+
## Example Sites
45+
46+
- [This repo itself](https://btholt.github.io/gatsby-course-starter/)
47+
- [Complete Intro to Containers](https://btholt.github.io/complete-intro-to-containers/)
48+
- [Complete Intro to React v5](https://btholt.github.io/complete-intro-to-react-v5/)
49+
- [Complete Intro to Web Dev v2](https://btholt.github.io/intro-to-web-dev-v2/)
50+
- [Four Semesters of Computer Science in Five Hours Part II](https://btholt.github.io/four-semesters-of-cs-part-two/)
51+
52+
## CSV
53+
54+
If you run `npm run csv`, a CSV will be generated with all the various lessons' frontmatter outputted to `public/lessons.csv`. You can change the path by changing the `OUTPUT_CSV_PATH` environment variable.
55+
56+
Another CSV will be output to `public/links.csv` where it pull all the links out of each lesson and put them into a CSV. This path can be modified by setting the `LINKS_CSV_PATH` environment variable.
57+
58+
## License
59+
60+
The **code** is this repo is licensed under the Apache 2.0 license.
61+
62+
I include the CC-BY-NC-4.0 license for the content; this is what I recommend you license your **content** under: anyone can use and share the content but they cannot sell it; only you can.

csv.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const fs = require("fs").promises;
2+
const path = require("path");
3+
const fm = require("front-matter");
4+
const isUrl = require("is-url-superb");
5+
const parseLinks = require("parse-markdown-links");
6+
const { sorter } = require("./src/util/helpers");
7+
const mdDir = process.env.MARKDOWN_DIR || path.join(__dirname, "lessons/");
8+
const outputPath =
9+
process.env.OUTPUT_CSV_PATH || path.join(__dirname, "public/lessons.csv");
10+
const linksOutputPath =
11+
process.env.LINKS_CSV_PATH || path.join(__dirname, "public/links.csv");
12+
13+
async function createCsv() {
14+
console.log(`making the markdown files into a CSV from ${mdDir}`);
15+
16+
// get paths
17+
const allFiles = await fs.readdir(mdDir);
18+
const files = allFiles.filter(filePath => filePath.endsWith(".md"));
19+
20+
// read paths, get buffers
21+
const buffers = await Promise.all(
22+
files.map(filePath => fs.readFile(path.join(mdDir, filePath)))
23+
);
24+
25+
// make buffers strings
26+
const contents = buffers.map(content => content.toString());
27+
28+
// make strings objects
29+
let frontmatters = contents.map(fm);
30+
31+
// find all attribute keys
32+
const seenAttributes = new Set();
33+
frontmatters.forEach(item => {
34+
Object.keys(item.attributes).forEach(attr => seenAttributes.add(attr));
35+
});
36+
const attributes = Array.from(seenAttributes.values());
37+
38+
if (attributes.includes("order")) {
39+
frontmatters = frontmatters.sort(sorter);
40+
}
41+
42+
// get all data into an array
43+
let rows = frontmatters.map(item => {
44+
const row = attributes.map(attr =>
45+
item.attributes[attr] ? JSON.stringify(item.attributes[attr]) : ""
46+
);
47+
return row;
48+
});
49+
50+
// header row must be first row
51+
rows.unshift(attributes);
52+
53+
// join into CSV string
54+
const csv = rows.map(row => row.join(",")).join("\n");
55+
56+
// write file out
57+
await fs.writeFile(outputPath, csv);
58+
59+
console.log(`Wrote ${rows.length} rows to ${outputPath}`);
60+
61+
// make links csv
62+
let longestLength = 0;
63+
let linksArray = frontmatters.map(row => {
64+
const links = parseLinks(row.body).filter(isUrl);
65+
longestLength = longestLength > links.length ? longestLength : links.length;
66+
const newRow = [row.attributes.order, row.attributes.title, ...links];
67+
return newRow;
68+
});
69+
70+
if (longestLength) {
71+
// add title row
72+
linksArray = linksArray.map(array => {
73+
const lengthToFill = longestLength + 2 - array.length;
74+
return array.concat(Array.from({ length: lengthToFill }).fill(""));
75+
});
76+
77+
linksArray.unshift(
78+
["order", "title"].concat(
79+
Array.from({ length: longestLength }).map((_, index) => `link${index}`)
80+
)
81+
);
82+
83+
// join into CSV string
84+
const linksCsv = linksArray.map(row => row.join(",")).join("\n");
85+
86+
// write file out
87+
await fs.writeFile(linksOutputPath, linksCsv);
88+
89+
console.log(`Wrote ${linksArray.length} rows to ${linksOutputPath}`);
90+
}
91+
}
92+
93+
createCsv();

gatsby-config.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
siteMetadata: {
3+
title: "Gatsby Starter Course",
4+
subtitle: "For making great content",
5+
description:
6+
"This is the description that will show up when people share as well as on search engines",
7+
keywords: [
8+
"this is",
9+
"a list of keywords and phrase",
10+
"that search engines",
11+
"will index your page for"
12+
]
13+
},
14+
//pathPrefix: "/my-repo-name", // if you're using GitHub Pages, put the name of the repo here with a leading slash
15+
plugins: [
16+
`gatsby-plugin-layout`,
17+
{
18+
resolve: `gatsby-source-filesystem`,
19+
options: {
20+
path: `${__dirname}/lessons`,
21+
name: "markdown-pages"
22+
}
23+
},
24+
`gatsby-plugin-react-helmet`,
25+
{
26+
resolve: `gatsby-transformer-remark`,
27+
options: {
28+
plugins: [
29+
`gatsby-remark-autolink-headers`,
30+
`gatsby-remark-copy-linked-files`,
31+
`gatsby-remark-prismjs`,
32+
{
33+
resolve: `gatsby-remark-images`,
34+
options: {
35+
maxWidth: 800,
36+
linkImagesToOriginal: true,
37+
sizeByPixelDensity: false
38+
}
39+
}
40+
]
41+
}
42+
}
43+
]
44+
};

gatsby-node.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const path = require("path");
2+
3+
exports.createPages = ({ actions, graphql }) => {
4+
const { createPage } = actions;
5+
6+
const lessonTemplate = path.resolve(`src/templates/lessonTemplate.js`);
7+
8+
return graphql(`
9+
{
10+
allMarkdownRemark(
11+
sort: { order: DESC, fields: [frontmatter___order] }
12+
limit: 1000
13+
) {
14+
edges {
15+
node {
16+
excerpt(pruneLength: 250)
17+
html
18+
id
19+
frontmatter {
20+
order
21+
path
22+
title
23+
}
24+
}
25+
}
26+
}
27+
}
28+
`).then(result => {
29+
if (result.errors) {
30+
return Promise.reject(result.errors);
31+
}
32+
33+
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
34+
createPage({
35+
path: node.frontmatter.path,
36+
component: lessonTemplate
37+
});
38+
});
39+
});
40+
};

lessons/images/logo.svg

Lines changed: 1 addition & 0 deletions
Loading

lessons/intro.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
path: "/intro"
3+
title: "Introduction"
4+
order: "1A"
5+
section: "The First Section"
6+
description: "this is the description that will show up in social shares"
7+
---
8+
9+
This is page one.
10+
11+
## Check out this image
12+
13+
![Gatsby Logo](./images/logo.svg)
14+
15+
## Check out a code sample
16+
17+
```js
18+
const x = 2 + 2;
19+
```
20+
21+
- This is a link to [Frontend Masters][fem].
22+
- This another link to [Brian Holt's Twitter](https://twitter.com/holtbt).
23+
- Here's another link to a [site built with this starter][containers].
24+
25+
[fem]: https://www.frontendmasters.com
26+
[containers]: https://btholt.github.io/complete-intro-to-containers/

lessons/page-2.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
path: "/page-2"
3+
title: "Page 2"
4+
order: "2A"
5+
description: "The second page"
6+
section: "The Second Section"
7+
---
8+
9+
This is page [two](https://en.wikipedia.org/wiki/2).

lessons/page-3.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
path: "/page-3"
3+
title: "Page 3"
4+
order: "2B"
5+
description: "The third page"
6+
section: "The Second Section"
7+
---
8+
9+
This is page three.
10+
11+
I think it is a good page.

0 commit comments

Comments
 (0)