#!/bin/bash
#===================================================================
# Filename   : jekyll.sh
# Function   :
# Usage      :
# Author     : Manford Fan
# Date       : 2021-08-29 13:10
# Version    : Version 0.1
# Disclaimer : The author is NOT responsible for any loss caused
#              by the user's own operations.
# And More   : If you find there are some bugs in this script
#              Or you have better ideas, please do contact me
#              via E-mail -- mffan0922@163.com
#===================================================================

# update blog
echo `date`
rm -rf /opt/websites/blog
let numOfAvatar=`ls /opt/websites/nav/assets/images/logos/ | wc -l`
let randNumber=$RANDOM%$numOfAvatar

cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/websites/homepage/assets/img/logo.jpg -rf
cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/source-code/blog/img/avatar.jpg -rf
cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/websites/nav/assets/images/logos/avatar.jpg -rf
jekyll b -s /opt/source-code/blog/ -d /opt/websites/blog/

# update bash
rm -rf /opt/websites/just-the-docs/bash
jekyll b -s /opt/source-code/document/bash -d /opt/websites/just-the-docs/bash

# update python
rm -rf /opt/websites/just-the-docs/python
jekyll b -s /opt/source-code/document/python -d /opt/websites/just-the-docs/python

chown -R www-data:www-data /opt/websites

