From 22fe36ad0a4382689ac46d54141699e6036b2027 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 21 Mar 2017 16:41:17 +0100 Subject: [PATCH] Added simple shell script for generating HTML overviews of the overlay contents --- .gitignore | 1 + .gitlab-ci.yml | 4 +- .gitlab-pages-generator.sh | 104 +++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100755 .gitlab-pages-generator.sh diff --git a/.gitignore b/.gitignore index b25c15b..83239ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +.public/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5e9d5e9..c4afbfa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,8 +12,8 @@ pages: only: - master script: - - mkdir .public - - mv * .public + - chmod +x .gitlab-pages-generator.sh + - ./gitlab-pages-generator.sh . .public - mv .public public artifacts: paths: diff --git a/.gitlab-pages-generator.sh b/.gitlab-pages-generator.sh new file mode 100755 index 0000000..24c7a0a --- /dev/null +++ b/.gitlab-pages-generator.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +ROOT=$(realpath "${1:-.}") +TARGET=$(realpath "${2:-.public}") +declare -a PARTS=() + +function createDir() { + mkdir -p "${1}" +} + +function createDirInTarget() { + local dirpart="${1}" + local destinationdirectory=${dirpart/${ROOT}/${TARGET}} + echo $destinationdirectory +} + +function writeHTMLHeader() { + local targetfile="${1}" + local currentdir="${2}" + + cat < "${targetfile}" + + + + + gentoo-overlay/${currentdir} + + +

gentoo-overlay/${currentdir}

+ + + +EOFOOT +} + +function writeHTMLFileentry() { + local targetfile="${1}" + local filename="${2}" + cat <> "${targetfile}" +
  • ${filename}
  • +EOFILE +} + +function pushPart() { + local part="${1}" + PARTS=("${PARTS[@]}" "${part}") +} + +function popPart() { + local index=$(expr ${#PARTS[@]} - 1) + unset PARTS[${index}] +} + +function renderParts() { + local IFS="/" + echo "${PARTS[*]}" +} + +function renderTargetPath() { + local parts=$(renderParts) + echo "${TARGET}${parts:+/}${parts}" +} + +function renderTargetFilename() { + local targetPath=$(renderTargetPath) + echo "${targetPath}/index.html" +} + +function processDir() { + local dir="${1}" + cd "${dir}" + local realpath=$(realpath .) + local files=$(ls) + local parts=$(renderParts) + local targetPath=$(renderTargetPath) + local targetFilename=$(renderTargetFilename) + mkdir -p "${targetPath}" + writeHTMLHeader "${targetFilename}" "${parts}" + writeHTMLFileentry "${targetFilename}" ".." + for f in ${files} ; do + if [ -f "${f}" ] ;then + cp "${f}" "${targetPath}" + writeHTMLFileentry "${targetFilename}" "${f}" + elif [ -d "${f}" ] ; then + writeHTMLFileentry "${targetFilename}" "${f}/" + pushPart "${f}" + processDir "${f}" + popPart + else + echo "Unknown: ${f}" + fi + done + writeHTMLFooter "${targetFilename}" + cd .. +} + +processDir "${ROOT}"