-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate-static.sh
42 lines (34 loc) · 1.25 KB
/
generate-static.sh
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
#!/usr/bin/env bash
#
# generate-static.sh - chriskempson.com
#
# Generates a static version of a locally hosted website and warns the user
# of any broken internal links.
STATIC_DIR="./static"
DOMAIN="127.0.0.1"
PORT="8000"
# Uncommenting this will create a version that works offline without being
# hosted locally as links such as 'pages/about' will become
# 'pages/about/index.php' and so on.
# PORTABLE="--convert-links"
# Off we go
printf "\n---- Scraping site with WGET...\n\n"
# Delete the previous scrape
rm --force --recursive $STATIC_DIR/*
# Build the static site by scraping localhost with wget and save the output
# of wget for processing with grep
RESULT=$(wget --recursive --page-requisites --no-parent --no-host-directories \
--execute robots=off --domains $DOMAIN --directory-prefix=$STATIC_DIR \
--restrict-file-names=nocontrol \
$PORTABLE \
http://$DOMAIN:$PORT/robots.txt \
http://$DOMAIN:$PORT \
2>&1)
# Display broken links
# Shows 4 lines above match so we can see the requested URL that has an issue
echo "$RESULT" | grep -B4 -i "failed\|error";
# Display stats
# For the curiously minded
echo "$RESULT" | grep -i "^finished\|^downloaded"
# The shows over
printf "\n---- Static site was exported to $STATIC_DIR\n\n"