File: build_html_docs.sh

package info (click to toggle)
cacti 1.2.30%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,176 kB
  • sloc: php: 123,193; javascript: 29,825; sql: 2,595; xml: 1,823; sh: 1,228; perl: 194; makefile: 65; python: 51; ruby: 9
file content (109 lines) | stat: -rwxr-xr-x 3,201 bytes parent folder | download
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
#!/bin/bash
#  +-------------------------------------------------------------------------+
#  | Copyright (C) 2004-2024 The Cacti Group                                 |
#  |                                                                         |
#  | This program is free software; you can redistribute it and/or           |
#  | modify it under the terms of the GNU General Public License             |
#  | as published by the Free Software Foundation; either version 2          |
#  | of the License, or (at your option) any later version.                  |
#  |                                                                         |
#  | This program is distributed in the hope that it will be useful,         |
#  | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
#  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
#  | GNU General Public License for more details.                            |
#  +-------------------------------------------------------------------------+
#  | http://www.cacti.net/                                                   |
#  +-------------------------------------------------------------------------+
#
# Helper script to build HTML documentation from markdown source

# define script variables
UTILS="pandoc"
ODIR="html"

# check if for required utilities
ERROR=""
for UTIL in ${UTILS}
do
	if ! which "${UTIL}" 1>/dev/null 2>&1
	then
		ERROR="${ERROR} - ${UTIL}\n"
	fi
done

if [ -n "${ERROR}" ]
then
	echo "ERROR: Required utilities not found"
	echo
	echo "Please install the following utilities:"
	echo "${ERROR}"
	exit 1
fi

# make sure pandoc has lua support

if ! pandoc --help | grep 'lua-filter' 1>/dev/null 2>&1
then
	echo "ERROR: Required LUA Filter support not found in Pandoc utility"
	echo "       Make sure you have version 2.3.1 or higher installed"
	exit 1
fi

# determine base path of the repository
BASE_PATH="$( cd "$(dirname "$0")" ; pwd -P | sed 's/\/bin//')"

# create output directory if needed
if [ ! -d "${BASE_PATH}/${ODIR}/images" ]
then

	if ! mkdir -p "${BASE_PATH}/${ODIR}/images"
	then
		echo "ERROR: Unable to create output directory: ${ODIR}"
		exit 1
	fi
fi

# copy image resources
echo "Copying images..."

if ! cp -r "${BASE_PATH}/images/"* "${BASE_PATH}/${ODIR}/images/"
then
	echo "ERROR: Failed to copy images"
	exit 1
fi

# copy css resourse
echo "Copying css..."

if ! cp -r "${BASE_PATH}/resources/css/"* "${BASE_PATH}/${ODIR}/"
then
	echo "ERROR: Failed to copy images"
	exit 1
fi

# process markdown files into html
echo "Converting files..."
for FILE in $(find "${BASE_PATH}" -maxdepth 1 -name "*.md")
do
	IFILE=${FILE//$BASE_PATH\/}
	OFILE=${ODIR}/${IFILE//.md/.html}
	TITLE=$(grep "^# " "$FILE" | head -1 | sed 's/# //')

	# handle special case for table of contents
	if [ "${IFILE}" = "README.md" ]
	then
		OFILE="${ODIR}/Table-of-Contents.html"
	fi
	echo "  '${IFILE}' => '${OFILE}'"

	pandoc --from=gfm --to=html5 "${IFILE}" \
	        --standalone \
		--output="${BASE_PATH}/${OFILE}" \
		--lua-filter="${BASE_PATH}/resources/build/pandoc_links_to_html.lua" \
		--css=Cacti-Github.css \
		--metadata=pagetitle:"$TITLE" \
		-T "Cacti"
done

# done
exit 0