Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add end-to-end example installation script #15

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ theme = ["your-main-theme", "hugo-shortcode-gallery"]
To read about hugo's theme components and how to use them have a look at
https://gohugo.io/hugo-modules/theme-components/.

### Shell script to setup a demo gallery

This [shell script](hugo_shortcode_gallery_generator.sh) sets up a hugo site including the short-code gallery and a couple of images.

`curl -sL https://raw.githubusercontent.com/RidaAyed/hugo-shortcode-gallery/CreateExampleSiteScript/hugo_shortcode_gallery_generator.sh | bash -s --`

## Usage Example

Expand Down
141 changes: 141 additions & 0 deletions hugo_shortcode_gallery_generator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/sh
if [ -z "$1" ]
#If first argument is empty set "/tmp" as working directory
then
OUT_DIR=/tmp
else
#Else set first argument as working directory
OUT_DIR=`pwd`"/$1"
fi
if [ -z "$2" ]
#If second argument is empty set "hugo" as sitename
then
SITE=mysite
else
#Else set second argument as sitename
SITE=$2
fi
if [ -z "$3" ]
#If third argument is empty set "hugo" as path
then
HUGOPATH=hugo
else
#Else set third argument as path
HUGOPATH=$3
fi

echo "Check if $OUT_DIR does not exist"
if [ ! -d "$OUT_DIR" ]
then
echo "Directory $1 DOES NOT exists. You can create it using: mkdir $1"
exit 9999 # die with error code 9999
fi

echo "Working directory is $OUT_DIR"

echo "Sitename is $SITE"
cd $OUT_DIR

echo "Kill any running hugo server"
sudo killall --quiet --signal SIGKILL hugo

echo "Remove any remnants from previous tests by \
uncommenting this line in the script or run it manually:"
echo `sudo rm --recursive --force --verbose $SITE`

echo "Generate a new site"
$HUGOPATH new site $SITE

echo "Get a lightweight theme"
cd $OUT_DIR/$SITE
git init
git submodule add https://github.com/de-souza/hugo-flex.git themes/hugo-flex

echo "Add the theme to the site's config"

echo 'theme = "hugo-flex"' >> config.toml

echo "Create a first post"
$HUGOPATH new posts/my-first-post.md

echo "Show what has been created"
cat ~$OUT_DIR/$SITE/content/posts/my-first-post.md

echo "Add the word 'foobar' and some others to the post"
printf '# foobar\nbar\n- lorem\n- ipsum' >> $OUT_DIR/$SITE/content/posts/my-first-post.md

echo "Start hugo server and build $SITE"
nohup $HUGOPATH server --buildDrafts &

echo "Do a test: \
Wait some time for hugo to generate the server, \
then get the website and assert it contains the word foo in it's html source \
by grepping it in the html source \
(you might have to do this manually if $SITE is cluttering your terminal"
sleep 3s

echo `curl -s http://localhost:1313/ | grep 'foobar'`

echo "Kill any running hugo server"
sudo killall --quiet --signal SIGKILL hugo

echo "Remove any remnants from previous tests by \
uncommenting this line in the script or run it manually:"
echo `sudo rm --recursive --force --verbose $OUT_DIR/$SITE/themes/hugo-shortcode-gallery`

echo "Cloning the hugo-shortcode-gallery git repository into $OUT_DIR/$SITE/themes."
git submodule add https://github.com/mfg92/hugo-shortcode-gallery.git themes/hugo-shortcode-gallery

echo "Adding this theme to $OUT_DIR/$SITE/config.toml using GNU sed"

echo `sed --debug -i 's/"hugo-flex"/\["hugo-flex", "hugo-shortcode-gallery"\]/' $OUT_DIR/$SITE/config.toml`

echo "Adding the gallery to the navigation in $OUT_DIR/$SITE/config.toml"
printf "
[[menu.nav]]
name = '"Gallery"'
url = '"gallery/"'
weight = 1
" >> $OUT_DIR/$SITE/config.toml

echo "Create the gallery and images folder"
mkdir --parents $OUT_DIR/$SITE/content/gallery/images

echo "Create the index.md in the gallery folder"
cd $OUT_DIR/$SITE
$HUGOPATH new /gallery/index.md

echo "Check content of index.md"
cat $OUT_DIR/$SITE/content/gallery/index.md

echo "Download some images into gallery/images"
cd $OUT_DIR/$SITE/content/gallery/images
wget --no-verbose https://raw.githubusercontent.com/mfg92/hugo-shortcode-gallery/example_site/example_site/content/gallery/images/2020-06-18-_MG_9066.jpg
wget --no-verbose https://raw.githubusercontent.com/mfg92/hugo-shortcode-gallery/example_site/example_site/content/gallery/images/2020-07-26-_MG_3439.jpg

echo "Adding the shortcode to index.md"
printf 'Here is an example gallery:

{{< gallery
match="images/*"
showExif="true"
sortOrder="desc"
loadJQuery="true"
embedPreview="true"
>}}' >> $OUT_DIR/$SITE/content/gallery/index.md

echo "cd into $OUT_DIR/$SITE and build the site"
cd $OUT_DIR/$SITE
nohup $HUGOPATH server --buildDrafts &

echo "Do a test: \
Wait some time for hugo to generate the server, \
then visit the gallery and assert it contains the string 'jpg', \
by grepping it in the html source \
(you might have to do this manually if hugo is cluttering your terminal"
sleep 3s

echo `curl -s http://localhost:1313/gallery/ | grep 'jpg'`

echo "Visit http://localhost:1313/gallery/ using your default browser"
xdg-open http://localhost:1313/gallery/