Commit 18857878 authored by Bram Daams's avatar Bram Daams
Browse files

Merge branch 'env' into 'main'

settings MAILER en AUTHOR verhuizen naar .env file

See merge request !21
parents 23ccdef5 1785a75e
Pipeline #66633 passed with stages
in 21 seconds
# your name as used in front matter and data/cncz.toml
AUTHOR=jenaam
# where to put cpk mail text: 'thunderbird', 'clipboard' or 'stdout'
MAILER=thunderbird
\ No newline at end of file
venv
content/cpk/teststoring.*.md
public
.hugo_build.lock
.env
AUTHOR
.mailer
/AUTHOR
......@@ -18,9 +18,23 @@ in de nieuwe content-files, de inhoud moet je zelf nog even typen.
## Initialisatie
In je eigen branch, zet een `AUTHOR` file neer met een unieke naam voor jezelf
(1 woord, kort) in de bovenste directory van de repository; De uitgebreide
informatie kun je invullen of controleren in `data/cncz.toml`
In je eigen branch, maak een .env file:
```
cp .env.dist .env
```
En pas de waardes aan.
Content van `.env.dist`:
```
# your name as used in front matter and data/cncz.toml
AUTHOR=jenaam
# where to put cpk mail text: 'thunderbird', 'clipboard' or 'stdout'
MAILER=thunderbird
```
## Front Matter
......
......@@ -78,6 +78,20 @@ cpkbody() {
-e 's/\[(.*)\]\(.*\)/\1/g' | $FMT
}
askauthor() {
echo -n "Do you want to use \"$(whoami)\" as author-id? (Y/N)"
read ANSWER
case "$ANSWER" in
Y | J | y | yes | ja | Yes | Ja)
AUTHOR=$(whoami)
echo "AUTHOR=$AUTHOR" >>$contentdir/../.env
;;
*)
echo "Please create an \".env\" with the variable AUTHOR in it, see README.md" >&2
exit 1
;;
esac
}
case $(basename $0) in
firstcpk)
......@@ -125,15 +139,25 @@ mailcpk)
echo source: https://cncz.science.ru.nl/en/cpk/$cpknumber
) > $tmpfile
mailerfile=$(dirname $0)/../.mailer
if [ -f $(dirname $0)/../.env ]; then
source $(dirname $0)/../.env
fi
if [ ! -f $mailerfile ]; then
echo "ERROR: could not find $mailerfile. Please create one with either the string 'thunderbird', 'clipboard' or 'stdout' in it"
exit 1
if [ -z "$MAILER" ]; then
echo "MAILER not found in .env"
if [ -f $(dirname $0)/../.mailer ]; then
MAILER=$(<$(dirname $0)/../.mailer)
echo "MAILER=$MAILER" >> $(dirname $0)/../.env
rm $(dirname $0)/../.mailer
fi
fi
if [ -z "$MAILER" ]; then
MAILER=stdout
fi
mailer=$(<$mailerfile)
compose_$mailer "$(cpksubject $cpknumber $nl $en)" $tmpfile
compose_$MAILER "$(cpksubject $cpknumber $nl $en)" $tmpfile
rm $tmpfile
exit 0
......
......@@ -14,8 +14,8 @@ slugify() {
}
get_abs_filename() {
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
template=$(basename $0).md
......@@ -36,24 +36,41 @@ if [ -z "$*" ]; then
exit 1
fi
if [ -f $contentdir/../AUTHOR ]; then
AUTHOR=$(cat $contentdir/../AUTHOR)
if [ -z "$AUTHOR" ]; then
echo "AUTHOR should not be empty" >&2
exit 1
fi
else
askauthor() {
echo -n "Do you want to use \"$(whoami)\" as author-id? (Y/N)"
read ANSWER
case "$ANSWER" in
Y|J|y|yes|ja|Yes|Ja)
AUTHOR=$(whoami)
echo "$AUTHOR" >$contentdir/../AUTHOR
;;
*) echo "Please create an \"AUTHOR\" file, see README.md" >&2
exit 1
;;
Y | J | y | yes | ja | Yes | Ja)
AUTHOR=$(whoami)
echo "AUTHOR=$AUTHOR" >>$contentdir/../.env
;;
*)
echo "Please create an \".env\" with the variable AUTHOR in it, see README.md" >&2
exit 1
;;
esac
}
if [ -f $contentdir/../.env ]; then
source $contentdir/../.env
fi
if [ -z "$AUTHOR" ]; then
# author niet gezet, misschien staat het nog in AUTHOR file
if [ -f $contentdir/../AUTHOR ]; then
AUTHOR=$(cat $contentdir/../AUTHOR)
if [ -z "$AUTHOR" ]; then
rm $contentdir/../AUTHOR
echo "Removed empty AUTHOR file"
exit 1
fi
# voeg author toe aan .env file
echo "AUTHOR=$AUTHOR" >>$contentdir/../.env
rm $contentdir/../AUTHOR
else
echo "Please create an \".env\" with the variable AUTHOR in it, see README.md" >&2
exit 1
fi
fi
export title="$*"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment