I noticed @cblte commenting on a post that is 3 years old now, and I went to take a look at how much my script to generate content changed since then.
Here are the useful bits in case someone needs a similar script:
#!/bin/bash
EDITOR=code
GREEN=$(tput -T screen setaf 2)
POWDER_BLUE=$(tput -T screen setaf 153)
NORMAL=$(tput sgr0)
if [[ $1 = "story" ]]; then
#statements
## Usage
# `new STORY TITLE-with-dashes`
# `new story section section-name`
if [[ $2 = 'section' ]]; then
hugo new story/"$3"/_index.md
open content/story/"$3"/
else
export STORY=$2
export SLUG=$3
DATE=`date "+%Y-%m-%d"`
hugo new story/$STORY/$DATE-$SLUG/index.md
export DESTINATION="content/story/$STORY/$DATE-$SLUG"
mkdir -p $DESTINATION/gallery;
mkdir -p $DESTINATION/images/;
open $DESTINATION/; $EDITOR $DESTINATION/; cd $DESTINATION/;
printf "\n$DESTINATION\n";
fi
fi
if [[ $1 = "post" ]]; then
#statements
# POSTS
export SLUG=$2
DATE=`date "+%Y-%m-%d"`
hugo new post/$DATE-$SLUG/index.md
mkdir -p content/post/$DATE-$SLUG/gallery;
mkdir -p content/post/$DATE-$SLUG/images/;
open content/post/$DATE-$SLUG/; $EDITOR content/post/$DATE-$SLUG/; cd content/post/$DATE-$SLUG/;
fi
# This was a special project that needed a new page every day
# Usage: `./new pagina-tantas`
if [[ $1 = "paginas-tantas" ]]; then
printf "\n ${POWDER_BLUE}### Creating files ###\n${NORMAL}"
FILE_EN=`date +%Y-%m-%d`
FILE_PT=`date +%Y-%m-%d`
hugo new stories/paginas-tantas/$FILE_EN/index.md;
hugo new stories/paginas-tantas/$FILE_PT/index.pt.md;
sed -i'' -e 's/draft\: true/draft\: false/g' content/story/paginas-tantas/$FILE_EN/index.md;
sed -i'' -e 's/draft\: true/draft\: false/g' content/story/paginas-tantas/$FILE_PT/index.pt.md;
sed -i'' -e 's/stories\:/stories\: \[\"paginas-tantas\"\]/g' content/story/paginas-tantas/$FILE_EN/index.md;
sed -i'' -e 's/stories\:/stories\: \[\"paginas-tantas\"\]/g' content/story/paginas-tantas/$FILE_PT/index.pt.md;
rm content/story/paginas-tantas/$FILE_EN/index.md-e
rm content/story/paginas-tantas/$FILE_PT-e/index.pt.md-e
printf "\n ${POWDER_BLUE}### Opening files ###\n${NORMAL}"
$EDITOR content/story/paginas-tantas/$FILE_PT/;
open content/story/paginas-tantas/$FILE_EN/index.md;
fi
# I think Hugo now does this on it's own.
if [[ $1 = 'undraft' ]]; then
DATE=`date "+%FT%TZ"`
gsed -i "s/date:.*$/date: ${DATE}/g" $2;
gsed -i "/draft: true/d" $2;
fi
# Send it to github
if [[ $1 = 'publish' ]]; then
if [[ $2 ]]; then
commit_message="$2"
else
commit_message="novo post"
fi
git add --all ; git commit -am "$commit_message" ; git push;
fi
if [[ $1 = 'deploy' ]]; then
printf "\n${GREEN}### Pushing changes and building on the other side ###\n${NORMAL}"
git push && ssh -t DeLorean 'cd Digital-Insanity; ./build.sh'
fi
if [[ $1 = 'help' ]]; then
#statements
echo "${GREEN}post : ${NORMAL}creates a new post, sintax is :: new.sh post TITLE-with-dashes"
echo "${GREEN}story : ${NORMAL}creates a new post inside a story, sintax is :: new.sh story STORY-NAME TITLE-with-dashes"
echo "${GREEN}paginas-tantas : ${NORMAL}creates a new post insite the paginas-tantas story"
echo "${GREEN}publish : ${NORMAL}adds all files to git and commits the changes to the current branch"
echo "${GREEN}deploy : ${NORMAL}pushes any commits to origin and connects to the DeLorean server to run the build script"
fi
In archetypes, if I want to get the title from an env variable, I make sure to export it
export SLUG=$3
And to fetch it replacing the dashes:
title: "{{ replace (getenv "SLUG") "-" " " | title }}"
Hope this helps someone.