MultiPage Hugo Site Deployment with AWS Amplify

huangapple go评论62阅读模式
英文:

MultiPage Hugo Site Deployment with AWS Amplify

问题

我正在尝试使用这个主题 https://github.com/luizdepra/hugo-coder/ 部署一个网站,具体来说,我正在使用 AWS Amplify 测试这个 示例站点。我已经尝试过 Netlifynetlify.toml 配置了正确的构建步骤。它在 Netlify 上运行良好。

但是,我想部署到 AWS Amplify - 因为我有其他依赖项。这是我正在使用的定义:

version: 2
frontend:
  phases:
    build:
      commands:
        - hugo
  artifacts:
    baseDirectory: public
    files:
      - '**/*'
  cache:
    paths: []

构建日志实际上显示它成功构建了网站。甚至网站可以正常加载,但问题出现在 routes 部分。无法导航到其他子路由。

我认为这是一个与 "重写和重定向" 有关的问题,我可能需要单独配置这个部分,因为这不是一个单页面网站。我正在阅读 这个,但指南对于多页面站点部署不太清晰。

在 Amplify 上正确部署的方法是什么?


编辑#1

尾部斜杠和干净的 URL

为了创建干净的 URL 结构,例如 about 而不是 about.html,静态站点生成器如 Hugo 会为页面生成包含 index.html 的目录(/about/index.html)。Amplify 会根据需要自动添加尾随斜杠来创建干净的 URL。下表突出显示不同情况:

Amplify 表示它会自动处理这个,但在我的情况下似乎没有发生。是否有一种方法可以在 Amplify 上强制执行这个?

英文:

I am trying to deploy a site using this theme https://github.com/luizdepra/hugo-coder/, and to be specific I am testing with this example site on AWS Amplify. I have already tried Netlify, and the netlify.toml has the right build steps. It works great with Netlify.

BUT, I want to deploy to AWS Amplify - as I have other dependencies. This is the definition I am using:

version: 2
frontend:
  phases:
    build:
      commands:
        - hugo
  artifacts:
    baseDirectory: public
    files:
      - '**/*'
  cache:
    paths: []

The build logs actually show that the it successfully built the site. Even the site loads fine, but the issue is with the routes. Navigating to other sub-routes does NOT work.

I believe this is a problem with

Rewrites and redirects

And I may have to configure this section separately as this is NOT a single page website. I am reading this and the guide is not clear for a multi-page site deployment.

Whats the correct way to deploy this on Amplify?


EDIT#1

Trailing slashes and clean URLs

To create clean URL structures like about instead of about.html, static site generators such as Hugo generate directories for pages with an index.html (/about/index.html). Amplify automatically creates clean URLs by adding a trailing slash when required. The table below highlights different scenarios:

Amplify indicates it automatically handles this ^, but in my case it seems to not happen. Is there a way to force this on amplify?

答案1

得分: 0

问题解决如下:

  • 我将静态站点从 react 更改为 Hugo
  • 这引发了构建步骤的更改

但是... AWS Amplify 已经正确执行了其工作。真正的问题出在了Rewrites and redirects中关于react的单页面设置。移除这些设置有助于解决路由问题,因为Amplify会自动处理这些设置。

英文:

The issue was resolved as follows:

  • I was changing the static site from react to Hugo
  • This induced a build step change

BUT ... AWS Amplify did its job correctly. The real issue was with single page settings for react in the Rewrites and redirects. Removing those settings helped get the routing issue addressed, as Amplify handles these automatically.

huangapple
  • 本文由 发表于 2023年2月24日 15:08:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553506.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定