Skip to content
update-gh-pages 1.6 KiB
Newer Older
Fabrice Salvaire's avatar
Fabrice Salvaire committed
#! /bin/bash

####################################################################################################

root_dir=$(dirname $(dirname $(realpath $0)))
html_build="${root_dir}/doc/sphinx/build/html"
source_gh_pages=${root_dir}/gh-pages

echo Source Path: ${root_dir}
echo HTML Build Path: ${html_build}

origin='git@github.com:FabriceSalvaire/PythonicGCodeMachine.git'

####################################################################################################

tmp_dir=$(mktemp -d)
if [ -e ${tmp_dir} ]; then
  pushd ${tmp_dir}

  # To create gh-pages branch
  # git clone ${origin} PythonicGCodeMachine-gh-pages
  # pushd PythonicGCodeMachine-gh-pages
  # git checkout --orphan  gh-pages
  # git rm --cached -r .

  git clone ${origin} PythonicGCodeMachine-gh-pages --branch gh-pages --single-branch
  pushd PythonicGCodeMachine-gh-pages
  # sync with origin if already cloned
  # git fetch origin
  git checkout gh-pages

  rm -rf static images
  rsync --delete -av --exclude-from=${source_gh_pages}/html-rsync-filter.txt ${html_build}/ .
  cp ${source_gh_pages}/README.rst .
  if [ -e _images ]; then
    mv _images images
    find . -name "*.html" -exec sed -e 's/_images/images/g;' -i {} \;
  fi
  if [ -e _static ]; then
    mv _static static
    find . -name "*.html" -exec sed -e 's/_static/static/g;' -i {} \;
  fi
  if [ -e _downloads ]; then
    mv _downloads downloads
    find . -name "*.html" -exec sed -e 's/_downloads/downloads/g;' -i {} \;
  fi
  find . -name '.#*html' -exec rm {} \;

  git add --all *
  git commit -m 'update'
  git push -u origin gh-pages

  popd -1 ; popd
  rm -rf ${tmp_dir}
fi