The code to generate https://blog.scottnonnenberg.com, a Gatsby-based blog.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci
assets
css
loaders/markdown-loader
pages
scripts
src
test
wrappers
.babelrc
.eslintignore
.eslintrc.js
.gatsby-context.js
.gitignore
CHANGELOG.md
LICENSE.txt
README.md
blog.sublime-project
config.toml
config_staging.toml
gatsby-browser.js
html.js
package.json

README.md

https://blog.scottnonnenberg.com

A gatsby-based blog.

More on how to use this project: https://blog.scottnonnenberg.com/this-blog-is-now-open-source/

continous integration code coverage license

Key settings

config.toml contains key data you'll want to change first. The location of the blog, author name and details, and so on.

piwik.js is excluded from the repository, but is used by html.js (to generate piwik tracking tags) and scripts/update_rankings.js (to get popularity numbers for posts). These four keys are required to use those features:

export default {
  url: 'usually something like "http://domain/piwik.php"',
  id: 'the site number',
  js: 'where to load your js from like "http://domain/piwik.js"',
  token: 'your API access token, used by `update-rankings` npm script',
  domain: 'used only for update-rankings task; like http://domain'
};

mailchimp.js is also excluded from the repository, used by the <EmailSignup> React component in displaying its form. It uses five keys:

export default {
  account: 'your account name, the first part of your mailchimp links',
  shard: 'the second component of your mailchimp links - like "us12"',
  u: 'the "u" value in your embedded mailchimp form',
  id: 'the "id" value in your embedded mailchimp form',
  fakeField: 'the field for robots in the embedded mailchimp form',
};

Note: if you don't want to use these features, put empty files at /piwik.js and /mailchimp.js (like export default {};) to make things work until you take the unused code out.

Develop

npm run develop

This runs gatsby's hot-reloading development server on http://localhost:8000. It will have to be restarted if you rename, add, or remove files because webpack's watch mode doesn't handle those kinds of filesystem changes.

Build

Generate files to public/ folder. Will fail if there are outstanding git changes. Pre-gzips all files. Calls a shell script behind the scenes, so you might run into some problems on Windows.

npm run build-production # or npm run build-staging
npm run build-production -- --force # build even with outstanding git changes

Test

Run eslint and the unit tests with npm test. All utility code and React components will be tested in Node.js. npm run unit will just run the tests, and unit-watch and unit-coverage are also available for active development. Once you've generated code coverage numbers, npm run open-coverage makes it easy to open istanbul's HTML report.

You can use npm run serve to serve static files from public/ at http://localhost:8000 for manual and automated tests. A manual test script is available at tests/manual.txt - it covers the parts of the user experience without automated tests.

Once you have the static server running you can check for broken links:

npm run check-local-links
npm run check-external-links
npm run check-deep-links
npm run check-links http://localhost:8000/

Note: Due to the meta tags on each page, you'll get broken links until you've published all pages to production.

Helper scripts

npm run make-post -- "The name of your post"

Creates a new markdown file from the template at scripts/util/_postTemplate.md. Sets the new post's previous URL to the last most-recent post's URL, and updates the previous post's markdown file with the newly-generated posts URL. That was annoying to do by hand. :0)

npm run clean-post
npm run clean-post -- 5

By default processes the most recent file. If a number is provided, it will process that many most-recent posts. Removes smart quotes, duplicate links (same text as URL), and all mentions of the blog's domain (taken from config.toml) to ensure that links are all of the relative form.

npm run generate-tags

Loads all posts from pages/posts and extracts all of their tags. Ensures that a file pages/tags/TAG.js exists for every tag found. Prints out a count for each.

npm run update-rankings

Goes to my stats system (which uses Piwik), grabs the top URLs, massages the data a little bit, then updates the rank property of the frontmatter in each markdown file. If you use this, you'll want to periodically change the end date for the query.

npm run generate-rss

Generates rss.xml and atom.xml into public/. Runs as part of every build.

npm run generate-json

Generates all.json and recent.json into public/. Also runs as part of every build. I generate this file for easier syndication into other sites, like https://scottnonnenberg.com.

Contributing

This project uses standard-version to release new versions, automatically updating the version number and changelog based on commit messages in standard format. ghooks and validate-commit-msg are used to ensure all commit messages match the expected format (see package.json for the configuration details).

It takes some getting used to, but this configuration is absolutely worthwhile. A changelog is way easier to understand than the chaos of a raw commit stream, especially with standard-version providing direct links to bugs, commits and commit ranges.

TODO

License

The files under pages/posts are Copyright 2016, All Rights Reserved.

The rest of the project is under the MIT license:

Copyright (c) 2016 Scott Nonnenberg scott@nonnenberg.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.