3
votes

I'm using Hugo on Github Pages, and whenever I push my site to origin, I get this error message sent to my email:

The page build failed for the master branch with the following error: There was a YAML syntax error on line 2 column 1 in <unknown>: did not find >expected key while parsing a block mapping. For more information, see >https://help.github.com/articles/page-build-failed-invalid-yaml-in-data-file/. For information on troubleshooting Jekyll see: https://help.github.com/articles/troubleshooting-jekyll-builds If you have any questions you can contact us by replying to this email.

How can I fix this? I heard making a .nojekyll file in root helps, but I don't know how to do that

I've tried some solutions online that didn't work, and I created a nojekyll.nojekyll file in root to hopefully disable Jekyll, if that's the problem...

2
Did you check the deploy documentation : gohugo.io/hosting-and-deployment/hosting-on-github ?David Jacquel

2 Answers

4
votes

Use .nojekyll to tell Github to not process your files with Jekyll, so after you build the site, just place a .nojekyll file at the root of the gh-page or in the docs folder.

For example, move all the files generated by Hugo to a docs folder and place a .nojekyll empty file in /docs. Then choose the docs folder as the container of the Github pages files and Github will serve those files.

If you want to see a live example, I'm using that approach in this theme https://github.com/marcanuy/simpleit-hugo-theme and works fine, with the resulting website being served at https://marcanuy.github.io/simpleit-hugo-theme/ using the following Make recipe to do it automatically:

generate-githubpages:
    rm -fr docs && HUGO_ENV=production $(HUGO) --baseURL https://marcanuy.github.io/simpleit-hugo-theme/ --source=exampleSite --themesDir=../.. --config ../config-github-docs.toml && mv exampleSite/public docs && touch docs/.nojekyll
clean:
    rm -fr exampleSite/public/

You can read more at Read more at Publishing your GitHub Pages site from a /docs folder on your master branch).

0
votes

I happened to have this problem too! I think the easiest solution is:

  1. put your source code into a branch, e.g. source
  2. deploy your site on the master branch only.

see how to set this up using github action template for hugo here: https://github.com/peaceiris/actions-gh-pages

here is my gh-pages.yaml

  1. set source branch
    name: Publish Site
    on: 
    push:
        branches:
        - source  # default branch
    
  2. set publish_branch: master, or not work
    - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
            deploy_key: ${{ secrets.SSH_DEPLOY_KEY }}
            publish_dir: ./public
            publish_branch: master  # deploying branch