From ce08c3d4d884a2a46c7302fada3bf921acd08a3c Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 20 Mar 2020 16:24:28 +0000 Subject: [PATCH] add option to install theme with hugo --- config.sh | 7 ++++-- dev-setup/hugo.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/config.sh b/config.sh index eb1d099..0430986 100644 --- a/config.sh +++ b/config.sh @@ -1,8 +1,11 @@ -export _url="hugo-skeleton.home" -export _user='ray' +export _url=hugo-skeleton.home +export _user=ray export _node_version=v12.16.1 export _node_distro=linux-x64 export _hugo_version=0.67.1 export _hugo_distro=Linux-64 +export _hugo_theme_git_url=https://github.com/dirkolbrich/hugo-theme-tailwindcss-starter +export _hugo_theme_name=hugo-theme-tailwindcss-starter +export _hugo_site_name=hugo-site-tailwindcss-starter diff --git a/dev-setup/hugo.sh b/dev-setup/hugo.sh index 76c0779..dd52db9 100755 --- a/dev-setup/hugo.sh +++ b/dev-setup/hugo.sh @@ -2,5 +2,55 @@ set -e -wget https://github.com/gohugoio/hugo/releases/download/v"$_hugo_version"/hugo_extended_"$_hugo_version"_"$_hugo_distro"bit.deb -O /tmp/hugo.deb -apt-get install /tmp/hugo.deb +_cmd_su="su --login $_user -c" +_site_path="/home/$_user/$_hugo_site_name" +_theme_path="$_site_path/themes/$_hugo_theme_name" +_serve_script_path="$_site_path/hugo-serve.sh" +_build_script_path="$_site_path/hugo-build.sh" + +if ! command -v hugo ; then + if command -v apt-get ; then + wget https://github.com/gohugoio/hugo/releases/download/v"$_hugo_version"/hugo_extended_"$_hugo_version"_"$_hugo_distro"bit.deb -O /tmp/hugo.deb + apt-get install /tmp/hugo.deb + else + echo 'hugo.sh: Error - no installation method available for `hugo` executable' + exit 1; + fi +fi + +if command -v yarn ; then + $_cmd_su 'yarn global add postcss-cli autoprefixer' +else + echo 'hugo.sh: Error - `yarn` executable not found' + exit 1 +fi + +$_cmd_su "cd ~ && hugo new site $_hugo_site_name" + +if [ -z "$_hugo_theme_git_url" ] ; then + exit +fi + +$_cmd_su "git clone $_hugo_theme_git_url $_theme_path" + +$_cmd_su " rm -Rf $_theme_path/.git" +$_cmd_su "cd $_theme_path && git init" + +$_cmd_su "cd $_theme_path && yarn install" +echo "theme = \"$_hugo_theme_name\"" >> $_site_path/config.toml + +echo "#!/bin/sh" > "$_serve_script_path" +echo 'echo "sudo required to bind to port 80"' >> "$_serve_script_path" +echo "sudo hugo server -D --bind=0.0.0.0 --baseURL=http://$_url -p80" >> "$_serve_script_path" +chown "$_user": "$_serve_script_path" +chmod +x "$_serve_script_path" + +cat << EOF > "$_build_script_path" +#!/bin/sh + +touch ./public +rm -R ./public +hugo -v +EOF +chown "$_user": "$_build_script_path" +chmod +x "$_build_script_path"