Compare commits

..

10 Commits

2 changed files with 111 additions and 10 deletions

View File

@ -3,6 +3,11 @@
A script helping to statically generate websites using a combination of PHP,
HTML, and Markdown.
## Dependencies
- Bash
- PHP
## Usage
Synopsis: `isidore <command> [options]`
@ -13,8 +18,8 @@ Commands:
`<name>`.
- `build`: build the website (default).
- `clean`: cleans build files.
- `-h`, `--help`, `help`: show help information.
- `-V`, `--version`, `version`: show Isidore version number.
- `help`: show help information.
- `version`: show Isidore version number.
### New Project
@ -23,7 +28,7 @@ directory structure:
- `<dir>/`: the project directory.
- `site/`: contains the pages to be compiled.
- `templates/`: templates that can be used in `pages/` and can also be compiled.
- `templates/`: templates that can be used in `site/` and can also be compiled.
- `output/`: output directory of compiled HTML files.
- `config.php`: configuration file with Isidore configuration and global
variables.

View File

@ -23,6 +23,9 @@ ISIDORE_CONFIG_DIR_OPTIONS=(
"$HOME/.isidore")
ISIDORE_AUTHOR_NAME=""
PROG_NAME=$0
PROJECT_NAME="Isidore"
##
# Create the configuration file. This function is called if it does not already
# exist.
@ -52,7 +55,7 @@ function set_config_vars()
if [ -z "$ISIDORE_CONFIG_DIR" ]
then
if [ -z "$XDG_CONFIG_HOME" ]
if ! [ -z "$XDG_CONFIG_HOME" ]
then
ISIDORE_CONFIG_DIR="$XDG_CONFIG_HOME/isidore"
else
@ -71,9 +74,28 @@ function set_config_vars()
source $ISIDORE_CONFIG_DIR/config
}
##
# Print the usage of the Isidore command.
##
function print_usage()
{
echo "USAGE: $1 <command> [options]"
echo "USAGE: $PROG_NAME <command> [options]"
}
function print_help()
{
print_usage
echo -e "\nCOMMANDS:
new [-i] <dir>
Create a new Isidore project (use interactive mode with '-i')
build
Build the project rooted in the current directory
clean
Clean the built files
version
Print the current version
help
Show this help information"
}
##
@ -93,21 +115,36 @@ function check_in_project()
#
# Params:
# $1 - The project directory
# $2 - The project name
# $2 - Interactive mode (1 = true; 0 = false)
##
function new_project()
{
echo "$PROJECT_NAME v$ISIDORE_VERSION"
NEW_PROJECT_DIR=$1
NEW_PROJECT_NAME=$2
NEW_PROJECT_NAME="New Project"
NEW_PROJECT_URL="http://example.com/"
if [ $2 == 1 ]
then
echo -n "Project name: "
read NEW_PROJECT_NAME
echo -n "URL: "
read NEW_PROJECT_URL
fi
mkdir $NEW_PROJECT_DIR
mkdir -p $NEW_PROJECT_DIR/site/
mkdir -p $NEW_PROJECT_DIR/templates/
echo \
"<?php
\$site_name = \"$NEW_PROJECT_NAME\";
\$author = \"$ISIDORE_AUTHOR_NAME\";
\$site_author = \"$ISIDORE_AUTHOR_NAME\";
\$site_url = \"$NEW_PROJECT_URL\";
?>" >> $NEW_PROJECT_DIR/config.php
echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version
echo "New project created."
[ $2 == 0 ] &&
echo "Consider taking a look at the $NEW_PROJECT_DIR/config.php file."
}
##
@ -123,14 +160,73 @@ function clean_project()
echo "Project cleaned."
}
##
# Build the project.
##
function build_project()
{
check_in_project
mkdir -p ./output/
WORKDESK="/tmp/isidore-workdesk"
CFG_HEADER_FILE="$WORKDESK/config-header.php"
mkdir -p $WORKDESK
for i in $(find site/ -name '*.php')
do
echo "<?php include getcwd() . '/config.php'; ?>" > $CFG_HEADER_FILE
mkdir -p $WORKDESK/${i%/*}
cat $CFG_HEADER_FILE $i > $WORKDESK/$i
# the 4 offset is to avoid including `site/`
: ${i:4}
OUT_DIR="./output/${_%/*}"
mkdir -p $OUT_DIR
: ${i: :-4}
OUT_FILE="$OUT_DIR/${_##*/}"
php $WORKDESK/$i > $OUT_FILE
done
rm -r $WORKDESK
}
set_config_vars
case $1 in
new)
new_project $2 $3;;
if [ $# -lt 2 ]
then
echo "Insufficient number of arguments."
print_usage
exit 1
fi
INTERACTIVE=0
NEW_DIR=""
for i in ${@:2}
do
case $i in
-i)
INTERACTIVE=1;;
*)
if [ -z "$NEW_DIR" ]
then
NEW_DIR="$i"
else
echo "Unknown argument for new '$i'. Use the 'help' command."
print_usage
exit 1
fi
esac
done
new_project $NEW_DIR $INTERACTIVE;;
build)
build_project;;
clean)
clean_project;;
help)
print_help;;
version)
echo "$PROJECT_NAME v$ISIDORE_VERSION";;
*)
echo "Unknown command $1. Use the 'help' command."
print_usage $0;;
print_usage
exit 1;;
esac