基於 Gatsby.js 進行建置的個人部落格,其網站文章資料、分類設定與圖片檔案,需與 gatsby-jimmy-data 進行搭配。
- 2021/10/22: 升級至 Gatsby.js v4.0.0
- 2021/03/03: 升級至 Gatsby.js v3.0.0
- 2020/11/23: 開始遷移作業 Wordpress => Gatsby.js v2.26.1
開發測試時,可將 gatsby-jimmy-data 裡的 /src/content
資料夾下載下來,並將 DATA_SOURCE_BRANCH
設成 empty
。
DATA_SOURCE_BRANCH=empty
DATA_SOURCE_BRANCH=master
.env DATA_SOURCE_BRANCH
的值,需與 gatsby-config.js
進行配置。
module.exports = {
plugins: [
{
resolve: `gatsby-source-git`,
options: {
name: `gatsby-jimmy-data`,
remote: `https://github.com/jimmy010679/gatsby-jimmy-data.git`,
branch: process.env.DATA_SOURCE_BRANCH,
},
},
],
}
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `幻想吉米`,
short_name: `幻想吉米`,
start_url: `/`,
background_color: `#fff`,
theme_color: `#ebedf7`,
display: `standalone`,
icon: `src/images/icon.png`,
},
},
],
}
module.exports = {
plugins: [
{
resolve: "gatsby-plugin-sitemap",
options: {
...
output: `/sitemap`,
},
},
],
}
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-feed`,
options: {
...
},
},
],
}
網站使用 GTM 進行管理,並在 GTM 後台新增 GA。
module.exports = {
plugins: [
{
resolve: "gatsby-plugin-google-tagmanager",
options: {
id: "GTM-5FJWMKB",
includeInDevelopment: false,
defaultDataLayer: { platform: "gatsby" },
},
},
],
}
GitHub Action .github/workflows/node.js.yml
會使用到。
AWS_ACCESS_KEY_ID
: aws-access-key-idAWS_SECRET_ACCESS_KEY
: aws-secret-access-keyAWS_REGION
: aws-region
AWS_S3_BUCKET_MASTER
: Amazon S3 Master Bucket NameAWS_S3_BUCKET_PREVIEW
: Amazon S3 Preview Bucket NameAWS_S3_BUCKET_DEVELOP
: Amazon S3 Develop Bucket Name
AWS_CLOUDFRONT_ID_MASTER
: Amazon CloudFront - master branchAWS_CLOUDFRONT_ID_DEVELOP
: Amazon CloudFront - develop branch
AWS_ELASTICBEANSTALK_APPLICATION_NAME
: Amazon Elastic Beanstalk application-name (Preview Server)AWS_ELASTICBEANSTALK_ENVIRONMENT_NAME
: Amazon Elastic Beanstalk environment-name (Preview Server)
- 讀取上次 Gatsby cache 目錄 (
public
,.cache
) - 執行
$ npm install
- 執行
$ gatsby build
- 將產生的 /public 資料夾上傳到 Amazon S3 (
AWS_S3_BUCKET_MASTER
) - Amazon CloudFront 清除緩存 (
AWS_CLOUDFRONT_ID_MASTER
) - 將必要的原始 code 檔案壓縮成 zip 檔,檔名使用
env.SHA_VERSION
命名。 - 將 zip 檔上傳到 Amazon S3 (
AWS_S3_BUCKET_PREVIEW
) - Amazon ElasticBeanstalk 新增應用程式版本
AWS_ELASTICBEANSTALK_APPLICATION_NAME
,指定上述 zip 檔案。 - Amazon ElasticBeanstalk 將該環境
AWS_ELASTICBEANSTALK_ENVIRONMENT_NAME
切換到最新(上述)的應用程式版本。
- 讀取上次 Gatsby cache 目錄 (
public
,.cache
) - 執行
$ npm install
- 執行
$ gatsby build
- 將產生的 /public 資料夾上傳到 Amazon S3 (
AWS_S3_BUCKET_DEVELOP
) - Amazon CloudFront 清除緩存 (
AWS_CLOUDFRONT_ID_DEVELOP
)
master branch 只執行 1~5 點
curl
-X POST
-H "Authorization: token xxxxxxxx"
-H "Accept: application/vnd.github.v3+json"
https://api.github.com/repos/jimmy010679/gatsby-jimmy/actions/workflows/node.js.yml/dispatches
-d '{"ref":"master"}'`
- Production Server
- directions: 正式站點
- branch: master
- run:
gatsby build
- hosting: Amazon CloudFront + S3
- domain: https://kyjhome.com
- Preview Server
- directions: 預覽編輯文章用
- branch: master
- run:
ENABLE_GATSBY_REFRESH_ENDPOINT=true gatsby develop -p 8080
- hosting: Amazon Elastic Beanstalk
- Develop Server
- directions: 測試新功能用
- branch: develop
- run:
gatsby build
- hosting: Amazon CloudFront + S3
$ git clone git@github.com:jimmy010679/gatsby-jimmy.git
$ cd gatsby-jimmy
$ npm install
# develop
$ gatsby develop
# build
$ gatsby build