Repository navigation
Expand file tree
/
Copy pathgallerymaker.sh
More file actions
executable file
·110 lines (87 loc) · 2 KB
/
Copy pathgallerymaker.sh
File metadata and controls
executable file
·110 lines (87 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
# Defaults
HUGO_ROOT="/Volumes/Data/Users/ron/Sites/test_hugo/ronliskey_new"
GALLERY_ROOT="/static/img/gallery"
GALLERY_SECTION="gallery"
IMAGE_WIDTH=1200
THUMB_WIDTH=300
# Defaults that can be overwritten by command line.
THUMB_NAME="-thumb"
GALLERY="new-gallery"
function cd_hugo_root () {
cd ${HUGO_ROOT}
}
function cd_gallery_root () {
cd ${HUGO_ROOT}${GALLERY_ROOT}
}
function cd_gallery () {
cd ${HUGO_ROOT}${GALLERY_ROOT}/${GALLERY}
}
function usage()
{
echo "Usage: `basename $0` options (-d output_dir) (-t -thumbname) -h for help"
exit
}
function dir_error()
{
echo "\nERROR: That directory already exists!"
usage
}
pause(){
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n'
}
while getopts g:t:h? option
do
case "${option}"
in
g) GALLERY=${OPTARG};;
t) THUMB_NAME=${OPTARG};;
h|?) usage;;
esac
done
for pic in *".JPG"
do
if [[ -f "$pic" ]]
then
mv "${pic}" "${pic%.JPG}.jpg"
fi
done
for pic in *".PNG"
do
if [[ -f "${pic}" ]]
then
mv "${pic}" "${pic%.PNG}.png"
fi
done
OUTPUT_DIR=${HUGO_ROOT}${GALLERY_ROOT}/${GALLERY}
# Abort if directory already exists.
if [ -d "${OUTPUT_DIR}" ]; then
dir_error
fi
mkdir ${OUTPUT_DIR}
# Create resized image files.
for pic in *.jpg
do
convert ${pic} -resize ${IMAGE_WIDTH} ${OUTPUT_DIR}/${pic}
done
# Create thumbnail files.
for pic in *.jpg
do
cp "$pic" "${OUTPUT_DIR}/${pic%.jpg}${THUMB_NAME}.jpg"
done
# Resize thumbnail files.
for pic in ${OUTPUT_DIR}/*${THUMB_NAME}.jpg
do
convert ${pic} -resize ${THUMB_WIDTH} $pic
done
# Add index file to block directory view.
touch ${OUTPUT_DIR}/index.html
# Ensure all files have correct read permissions.
chmod go+r ${OUTPUT_DIR}/*.*
# Remove quarentine atribute if present. (OSX only)
find ${OUTPUT_DIR} -iname '*${THUMB_NAME}.jpg' -print0 | xargs -0 xattr -dr com.apple.quarantine
find ${OUTPUT_DIR} -iname '*${THUMB_NAME}.png' -print0 | xargs -0 xattr -dr com.apple.quarantine
clear
ls -l ${OUTPUT_DIR}
cd_hugo_root
hugo new gallery/${GALLERY}.md