Commit 2e12aa11 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

fix(pages): handle mkdocs output folder to already be 'public'

parent b4cff99e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ You might deploy the generated site using a [GitLab pages](https://docs.gitlab.c

### GitLab Pages variant

This variant adds a job to publish the MkDocs generated site to GitLab pages (on `master` branch only).
Basically it copies the content of the mkdocs generated site folder (`site` by default) to the `public` folder which is published by [GitLab pages](https://docs.gitlab.com/ee/user/project/pages/#how-it-works).

If you wish to use it, add the following to your `gitlab-ci.yml`:

+31 −2
Original line number Diff line number Diff line
@@ -12,12 +12,41 @@ variables:
stages:
  - publish

.mkdocs-scripts: &mkdocs-scripts |
  # BEGSCRIPT
  set -e

  function log_info() {
      echo -e "[\\e[1;94mINFO\\e[0m] $*"
  }

  function log_warn() {
      echo -e "[\\e[1;93mWARN\\e[0m] $*"
  }

  function log_error() {
      echo -e "[\\e[1;91mERROR\\e[0m] $*"
  }

  # ENDSCRIPT


pages:
  stage: publish
  before_script:
    - *mkdocs-scripts
  script:
    - mkdir -p public
    - cp -r ${MKD_WORKSPACE_DIR:-.}/${MKD_SITE_DIR:-site}/* public/
    - mkdocs_dist=${MKD_WORKSPACE_DIR:-.}/${MKD_SITE_DIR:-site}
    - target="public/"
    - |
      if [ "${mkdocs_dist}" -ef "${target}" ]
      then
        log_info "configured mkdocs site dir already is pages expected folder"
      else
        log_info "copying mkdocs generated site from \\e[33;1m${mkdocs_dist}\\e[0m to pages expected folder \\e[33;1m${target}\\e[0m"
        mkdir -p public
        cp -r ${mkdocs_dist}/* ${target}
      fi
  artifacts:
    paths:
      - public