---
# Publishes a hugo repo as GitLab pages.
# The job name must be pages for it to work.

pages:
  image:
    name: registry.gitlab.com/just-ci/images/hugo:latest
    entrypoint: [""]
  variables:
    MINIFY: "false"
    EXTRA_ARGS: ""
  stage: build
  # Add a before script to add an external theme, for example:
  # before_script:
  #   - git clone https://github.com/matcornic/hugo-theme-learn.git themes/hugo-theme-learn
  script:
    - |
      if [ ${MINIFY} = "true" ]; then
        hugo --minify ${EXTRA_ARGS}
        /minify.sh .
      else
        hugo ${EXTRA_ARGS}
      fi
    - gzip -kr public
    - |
      if [ ! "${CI_PROJECT_DIR}" = "${PWD}" ]; then
        mv public "${CI_PROJECT_DIR}/public"
      fi
    - |
      if [ "${CI_COMMIT_BRANCH}" = "${CI_DEFAULT_BRANCH}" ]; then
        echo "[!] When browing the test job artifacts you may not see the full final result when opening an HTML file, as the built site may reference absolute or canonified URLs."
      fi
  artifacts:
    paths:
      - public
    when: always
