aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-03-04 09:44:37 +0000
committerng0 <ng0@n0.is>2019-03-04 09:44:37 +0000
commite66580d759ceea6e6e9cb376f3ddb5a04d86fdf5 (patch)
tree6e2fde8b6a6a259ef5fe25f49c556cec6371bbce
parent9727890654820b85b13762524ccb210cfe6a1c2f (diff)
downloadwww-e66580d759ceea6e6e9cb376f3ddb5a04d86fdf5.tar.gz
www-e66580d759ceea6e6e9cb376f3ddb5a04d86fdf5.zip
A first initial draft for a sitemap
-rw-r--r--Makefile2
-rwxr-xr-xmake_sitemap.sh67
-rw-r--r--static/robots.txt2
3 files changed, 71 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 866377f6..02fd0cd3 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,8 @@ all: locale template
22 cp rendered/static/robots.txt rendered/es/robots.txt 22 cp rendered/static/robots.txt rendered/es/robots.txt
23 cp rendered/static/robots.txt rendered/fr/robots.txt 23 cp rendered/static/robots.txt rendered/fr/robots.txt
24 cp rendered/static/robots.txt rendered/it/robots.txt 24 cp rendered/static/robots.txt rendered/it/robots.txt
25 /bin/sh make_sitemap.sh
26 cp rendered/sitemap.xml rendered/en/sitemap.xml
25 27
26# Extract translateable strings from jinja2 templates. 28# Extract translateable strings from jinja2 templates.
27# Because of the local i18nfix extractor module we need 29# Because of the local i18nfix extractor module we need
diff --git a/make_sitemap.sh b/make_sitemap.sh
new file mode 100755
index 00000000..4777f948
--- /dev/null
+++ b/make_sitemap.sh
@@ -0,0 +1,67 @@
1#!/bin/sh
2
3# This initial version builds on code from ssg4
4# copyright is as follows:
5# -----
6# https://www.romanzolotarev.com/bin/ssg4
7# Copyright 2018 Roman Zolotarev <hi@romanzolotarev.com>
8#
9# Permission to use, copy, modify, and/or distribute this software for any
10# purpose with or without fee is hereby granted, provided that the above
11# copyright notice and this permission notice appear in all copies.
12#
13# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20# -----
21
22list_pages(){
23cd rendered && find . -type f ! -path '*/.*' ! -path '*/_*' -name '*.html' | sed 's#^./##;#'
24}
25
26main(){
27 dst=rendered
28 base_url="$4"
29 date=$(date +%Y-%m-%d)
30 urls=$(list_pages "$src")
31
32 test -n "$urls" &&
33 render_sitemap "$urls" "$base_url" "$date" > "$dst/sitemap.xml"
34
35 print_status 'url' 'urls' "$urls" >&2
36 echo >&2
37}
38
39print_status() {
40 test -z "$3" && printf 'no %s' "$2" && return
41
42 echo "$3" | awk -v singular="$1" -v plural="$2" '
43 END {
44 if (NR==1) printf NR " " singular
45 if (NR>1) printf NR " " plural
46 }'
47}
48
49render_sitemap() {
50 urls="$1"
51 base_url="$2"
52 date="$3"
53
54 echo '<?xml version="1.0" encoding="UTF-8"?>'
55 echo '<urlset'
56 echo 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
57 echo 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9'
58 echo 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"'
59 echo 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
60 echo "$urls" |
61 sed -E 's#^(.*)$#<url><loc>'"$base_url"'/\1</loc><lastmod>'\
62"$date"'</lastmod><priority>1.0</priority></url>#'
63 echo '</urlset>'
64}
65
66main "$@"
67
diff --git a/static/robots.txt b/static/robots.txt
index 0a639917..0c1fdbd0 100644
--- a/static/robots.txt
+++ b/static/robots.txt
@@ -16,5 +16,7 @@
16# For syntax checking, see: 16# For syntax checking, see:
17# http://www.frobee.com/robots-txt-check 17# http://www.frobee.com/robots-txt-check
18 18
19Sitemap: https://gnunet.org/en/sitemap.xml
20
19User-agent: * 21User-agent: *
20Crawl-delay: 10 22Crawl-delay: 10