使用 Ghost & Gatsby 建立閃電般快速網站的入門模板
示範: https://gatsby.ghost.org/
# With Gatsby CLI
gatsby new gatsby-starter-ghost https://github.com/TryGhost/gatsby-starter-ghost.git
# From Source
git clone https://github.com/TryGhost/gatsby-starter-ghost.git
cd gatsby-starter-ghost
然後安裝依賴項
yarn
啟動開發伺服器。您現在有一個 Gatsby 網站,從 Headless Ghost 中提取內容。
gatsby develop
預設情況下,啟動器將從位於 https://gatsby.ghost.io 的預設 Ghost 安裝中填入內容。
要使用您自己的安裝,您需要使用您的憑證編輯.ghost.json
設定檔。將apiUrl
值變更為您的 Ghost 網站的 URL。對於 Ghost(Pro) 客戶,這是以.ghost.io
結尾的 Ghost URL,對於使用 Ghost 自託管版本的用戶,它與用於訪問您的網站的 URL 相同。
接下來,將contentApiKey
值更新為與 Ghost 網站關聯的金鑰。可以透過在 Ghost Admin 中建立整合來提供金鑰。導航至整合並點擊“新增整合”。適當地命名整合並點擊“建立”。
最後,在siteConfig.js
中配置您所需的 URL,以便正確產生連結(例如規範連結)。您也可以更新其他預設值,例如此文件中的postsPerPage
。
要毫無問題地使用此啟動器,您的 Ghost 安裝版本至少需要為2.10.0
。
用於此啟動程序的預設 Ghost 版本是5.x
。如果您的 Ghost 安裝版本較低,則需要在.ghost.json
設定中傳遞version
屬性:
幽靈 >=2.10.0 <5.0.0
{
"apiUrl" : " https://gatsby.ghost.io " ,
"contentApiKey" : " 9cc5c67c358edfdd81455149d0 " ,
"version" : " v4.0 "
}
幽靈 >=5.0.0
{
"apiUrl" : " https://gatsby.ghost.io " ,
"contentApiKey" : " 9cc5c67c358edfdd81455149d0 "
}
Starter 包含三個專門用於使用 Netlify 進行部署的設定檔。用於建置設定的netlify.toml
檔案、為所有路由設定預設安全標頭的/static/_headers
檔案以及用於設定 Netlify 自訂網域重定向的/static/_redirects
。
要部署到您的 Netlify 帳戶,請點擊下面的按鈕。
內容 API 金鑰通常不被視為敏感訊息,它們的存在是為了在濫用時可以更改;所以大多數人直接將其提交到他們的.ghost.json
設定檔中。如果您希望將此資訊保留在儲存庫之外,您可以刪除此配置並為生產建置設定 Netlify ENV 變數。
部署後,您可以設定 Ghost + Netlify 集成,以使用 Ghost 中的部署掛鉤來觸發 Netlify 重建。這樣,只要 Ghost 中的資料發生變化,您的網站就會在 Netlify 上重建。
您可以透過在 Ghost 設定中啟用Make this site private
」標誌來停用預設的 Ghost Handlebars 主題前端。這會在 Ghost 安裝之前啟用密碼保護並設定<meta name="robots" content="noindex" />
以便您的 Gatsby 前端成為 SEO 的真實來源。
# Run a production build, locally
gatsby build
# Serve a production build, locally
gatsby serve
Gatsby develop
使用.ghost.json
中的development
配置 - 而 Gatsby build
使用production
配置。
版權所有 (c) 2013-2025 Ghost Foundation - 依據 MIT 許可發布。