Merge branch 'main' into 'main'

Rewrite as POSIX shell

See merge request cordelya/johnny-decimal!1
This commit is contained in:
Cordelya Sharpe 2024-01-16 22:19:36 +00:00
commit e591eaef41
2 changed files with 79 additions and 26 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 2024-12-16
- Rewrote build-index.sh to be POSIX-compliant
- build-index.sh now takes two arguments. The first is the root directory of the
JD system, and the second is the output directory.
## 2023-12-17
Repository created

View File

@ -1,35 +1,83 @@
#!/bin/bash
#!/bin/sh
# defin the target dir
parent=$(dirname "${BASH_SOURCE[0]}")
cd $parent; cd ../../../
directory=$(pwd -P)
# MIT License
#
# Copyright (c) 2023 Cordelya Sharpe
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
today=`date "+%Y-%m-%d"`
set -e
echo -e "Date: $today\n"
test -n "$DEBUG" && set -x
for dirs in "$directory"/*; do
string="---\n"
area=$(basename "${dirs}")
if [ "$area" != "System Volume Information" ]; then
if test -z "$2"; then
if test -z "$1"; then
# output to and read system from current dir if $1 and $2 are not set
out="$(pwd -P)"
root="$out"
else
# if $1 is set, that is the system root
root="$1"
fi
else
# if both $1 and $2 are set, they are the root and output dir
root="$1"
out="$2"
fi
string+="title: $area\n"
string+="date: $today\n"
string+="---\n\n"
for cats in "$dirs"/*; do
category=$(basename "${cats}")
string+="# $category\n\n"
for ids in "$cats"/*; do
ident=$(basename "${ids}")
string+="* $ident\n"
date="$(date "+%Y-%m-%d")"
# for every area dir in the root, get the basename of the area
for dir in "$root"/*; do
area="$(basename "$dir")"
# only include jd files
if test -n "$(printf '%s\n' "$area" | sed -n '/^[0-9][0-9]-.*/p')"
then
# set the filename to the area number for the filename of the index
fullpath="$out/$(printf '%s\n' "$area" | dd bs=5 count=1 2>/dev/null).md"
# if the file already exists, back it up
if test -f "$fullpath"; then
mv "$fullpath" "$fullpath.old"
fi
printf '%s: %s: Saving index as %s.\n' "$0" "$area" "$fullpath" 1>&2
# add front matter to markdown file
printf -- "---\ntitle: %s\ndate: %s\n---\n" "$area" "$date" >>"$fullpath"
# iterate through catergories
for c in "$dir"/*; do
category="$(basename "$c")"
# add category as a header to the output file
printf "# %s\n\n" "$category" >>"$fullpath"
# iterate through contents of categories
for i in "$c"/*; do
id="$(basename "$i")"
# add each content item to the output file
printf "* %s\n" "$id" >>"$fullpath"
done
string+="\n"
printf '\n' >>"$fullpath"
done
savedir="$directory/00-09 Index/00 Index/00.01 Index/"
fname="${area:0:5}.md"
fullpath="$savedir$fname"
echo $fullpath
echo -e $string > "$fullpath"
fi
done