问题描述
我使用 AWS Amplify 创建了一个非常简单的 gatsby 站点,站点地图不是由“gatsby-plugin-sitemap”创建的。
[package.json]
{
"name": "web_matching","version": "1.0.0","private": true,"description": "web_matching","author": "uekyo","keywords": [
"gatsby"
],"scripts": {
"develop": "gatsby develop","start": "gatsby develop","build": "gatsby build","serve": "gatsby serve","clean": "gatsby clean"
},"dependencies": {
"gatsby": "^2.26.1","gatsby-plugin-sitemap": "^2.11.0","react": "^16.13.1","react-dom": "^16.13.1"
}
}
[gatsby-config.js]
module.exports = {
siteMetadata: {
title: "web_matching",siteUrl: `https://amp.d1aw1cuurv9iud.amplifyapp.com`,},plugins: [
{
resolve: `gatsby-plugin-sitemap`,options: {
output: `/sitemap.xml`,}
}
]
};
[amplify.yml]
version: 1
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn build
artifacts:
baseDirectory: public
files:
- '**/*'
cache:
paths:
- node_modules/**/*
你们有同样的经历吗?顺便说一下,如果我输入站点地图 URL,它会自动移动到首页。但是,它适用于本地主机。问题似乎出在 Amplify 上。
解决方法
使用 gatsby develop
在本地运行不会提供站点地图。
您必须通过运行 gatsby build && gatsby serve
然后应该可以通过 http://localhost:9000/sitemap.xml
获得站点地图