This repository holds the code, written content and media for my personal website. It uses Gatsby to build Markdown and React content into a static HTML site that can easily be deployed to S3.
It's pretty simple. Clone, install and run. I suppose there's a few extra steps in there.
-
Clone and install.
I like Yarn, but NPM works too of course.
git clone git@github.com:ahadik/portfolio.git yarn install
-
Set up Firebase.
This site uses Firebase to authenticate restricted content. If you intend to use this feature, you'll need to set up a Firebase project, add Authentication, and create a user. You'll use the email address of that user in the next step.
-
Set up environment variables.
.env
files are used to set variables for different build environments. Copy the.sample.env
file and rename it to.env
if you intend to use the same values for every environment, or to.env.ENV
(.env.staging
for example) if you want different values for different environments. I have four.env
files:.env.development
: For values needed while viewing the site on the development server..env.local
: For values while viewing the production built site on a local server..env.staging
: For values needed for a staging environment..env.production
: For values needed for a staging environment.
cp .sample.env .env
There are six key pieces of information you'll need to expose in your .env file(s).
SITE_URL=<URL>
: The URL for accessing the site for this environmentFIREBASE_API_KEY=<API_KEY>
: Get it from the Firebase console.FIREBASE_AUTH_DOMAIN=<AUTH_DOMAIN>
: Get it from the Firebase console.FIREBASE_DATABASE_URL=<DATABASE_URL>
: Get it from the Firebase console.FIREBASE_PROJECT_ID=<PROJECT_ID>
: Get it from the Firebase console.FIREBASE_USER_EMAIL=<USER_EMAIL>
: This is the email address of a user you've set up in Firebase, the password of which will be used to authenticate restricted content.
-
Run the Gatsby dev server.
gatsby develop
-
Open the source code and start editing!
Your site is now running at
http://localhost:8000
!Note: You'll also see a second link:
http://localhost:8000/___graphql
. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the Gatsby tutorial.
A quick look at the top-level files and directories you'll see in this project.
.
βββ node_modules
βββ src
| βββ pages
| βββ content
| βββ components
| βββ data
| βββ images
| βββ services
| βββ templates
| βββ fragments.js
βββ scripts
βββ .gitignore
βββ .prettierrc
βββ gatsby-browser.js
βββ gatsby-config.js
βββ gatsby-node.js
βββ gatsby-ssr.js
βββ LICENSE
βββ package-lock.json
βββ package.json
βββ .sample.env
βββ README.md
-
/node_modules
: This directory contains all of the modules of code that this project depends on (npm packages) are automatically installed. -
/src
: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template.src
is a convention for βsource codeβ. -
/scripts
: This directory will contain scripts that help automate your work, such as creating a blank post (create-post.js
) or deploying (deploy.js
). -
.gitignore
: This file tells git which files it should not track / not maintain a version history for. -
.prettierrc
: This is a configuration file for Prettier. Prettier is a tool to help keep the formatting of your code consistent. -
gatsby-browser.js
: This file is where Gatsby expects to find any usage of the Gatsby browser APIs (if any). These allow customization/extension of default Gatsby settings affecting the browser. -
gatsby-config.js
: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins youβd like to include, etc. (Check out the config docs for more detail). -
gatsby-node.js
: This file is where Gatsby expects to find any usage of the Gatsby Node APIs (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process. -
gatsby-ssr.js
: This file is where Gatsby expects to find any usage of the Gatsby server-side rendering APIs (if any). These allow customization of default Gatsby settings affecting server-side rendering. -
LICENSE
: Gatsby is licensed under the MIT license. -
package-lock.json
(Seepackage.json
below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for this project. (You wonβt change this file directly). -
package.json
: A manifest file for Node.js projects, which includes things like metadata (the projectβs name, author, etc). This manifest is how npm knows which packages to install for this project. -
.sample.env
: A sample config file. Copy and rename it to start with.env
and it will automatically be ignored from Git tracking. Now you can store sensitive API keys and the like in it. -
README.md
: A text file containing useful reference information about this project.
Looking for more guidance? Full documentation for Gatsby lives on the website. Here are some places to start:
-
For most developers, we recommend starting with our in-depth tutorial for creating a site with Gatsby. It starts with zero assumptions about your level of ability and walks through every step of the process.
-
To dive straight into code samples, head to our documentation. In particular, check out the Guides, API Reference, and Advanced Tutorials sections in the sidebar.
I deploy this site to S3, so I use the scripts/deploy.js
script (accessible as a Yarn script with yarn deploy
and yarn deploy:<ENV>
β look in package.json
for more info) to upload my site after it's been built.
- Copy config files:
aws-config.ENV.js.example
is checked into source control and will have been cloned locally. Copy it for each environment:cp aws-config.ENV.js.example aws-config.staging.js
for a staging environment for example. This new file is ignored in.gitignore
by default if you follow these naming conventions. - Configure each
aws-config
file: You'll need to create the appropriate S3 buckets, an AWS access ID and secret, and fill in the corresponding info in your newly createdaws-config
files. - Build the site for production:
yarn build:<ENV>
whereENV
is either (local
,staging
, orproduction
). This will ensure the right URLs are used in the final build. - Deploy your built site:
node scripts/deploy.js --<ENV>
Your Gatsby built files should upload to S3 and you can take it from there!