Compare commits
10 Commits
b06f2b1a1c
...
76308dc9a9
Author | SHA1 | Date | |
---|---|---|---|
76308dc9a9 | |||
d997d829b5 | |||
e0faf6c069 | |||
8ab0657f29 | |||
77b8c82a6c | |||
593b389ccb | |||
8f2a2d0c2d | |||
d3713b6bad | |||
44d7def8d4 | |||
253ae30746 |
11
README.md
11
README.md
@ -3,6 +3,11 @@
|
|||||||
A script helping to statically generate websites using a combination of PHP,
|
A script helping to statically generate websites using a combination of PHP,
|
||||||
HTML, and Markdown.
|
HTML, and Markdown.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- Bash
|
||||||
|
- PHP
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Synopsis: `isidore <command> [options]`
|
Synopsis: `isidore <command> [options]`
|
||||||
@ -13,8 +18,8 @@ Commands:
|
|||||||
`<name>`.
|
`<name>`.
|
||||||
- `build`: build the website (default).
|
- `build`: build the website (default).
|
||||||
- `clean`: cleans build files.
|
- `clean`: cleans build files.
|
||||||
- `-h`, `--help`, `help`: show help information.
|
- `help`: show help information.
|
||||||
- `-V`, `--version`, `version`: show Isidore version number.
|
- `version`: show Isidore version number.
|
||||||
|
|
||||||
### New Project
|
### New Project
|
||||||
|
|
||||||
@ -23,7 +28,7 @@ directory structure:
|
|||||||
|
|
||||||
- `<dir>/`: the project directory.
|
- `<dir>/`: the project directory.
|
||||||
- `site/`: contains the pages to be compiled.
|
- `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.
|
- `output/`: output directory of compiled HTML files.
|
||||||
- `config.php`: configuration file with Isidore configuration and global
|
- `config.php`: configuration file with Isidore configuration and global
|
||||||
variables.
|
variables.
|
||||||
|
110
isidore.sh
110
isidore.sh
@ -23,6 +23,9 @@ ISIDORE_CONFIG_DIR_OPTIONS=(
|
|||||||
"$HOME/.isidore")
|
"$HOME/.isidore")
|
||||||
ISIDORE_AUTHOR_NAME=""
|
ISIDORE_AUTHOR_NAME=""
|
||||||
|
|
||||||
|
PROG_NAME=$0
|
||||||
|
PROJECT_NAME="Isidore"
|
||||||
|
|
||||||
##
|
##
|
||||||
# Create the configuration file. This function is called if it does not already
|
# Create the configuration file. This function is called if it does not already
|
||||||
# exist.
|
# exist.
|
||||||
@ -52,7 +55,7 @@ function set_config_vars()
|
|||||||
|
|
||||||
if [ -z "$ISIDORE_CONFIG_DIR" ]
|
if [ -z "$ISIDORE_CONFIG_DIR" ]
|
||||||
then
|
then
|
||||||
if [ -z "$XDG_CONFIG_HOME" ]
|
if ! [ -z "$XDG_CONFIG_HOME" ]
|
||||||
then
|
then
|
||||||
ISIDORE_CONFIG_DIR="$XDG_CONFIG_HOME/isidore"
|
ISIDORE_CONFIG_DIR="$XDG_CONFIG_HOME/isidore"
|
||||||
else
|
else
|
||||||
@ -71,9 +74,28 @@ function set_config_vars()
|
|||||||
source $ISIDORE_CONFIG_DIR/config
|
source $ISIDORE_CONFIG_DIR/config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##
|
||||||
|
# Print the usage of the Isidore command.
|
||||||
|
##
|
||||||
function print_usage()
|
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:
|
# Params:
|
||||||
# $1 - The project directory
|
# $1 - The project directory
|
||||||
# $2 - The project name
|
# $2 - Interactive mode (1 = true; 0 = false)
|
||||||
##
|
##
|
||||||
function new_project()
|
function new_project()
|
||||||
{
|
{
|
||||||
|
echo "$PROJECT_NAME v$ISIDORE_VERSION"
|
||||||
|
|
||||||
NEW_PROJECT_DIR=$1
|
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 $NEW_PROJECT_DIR
|
||||||
mkdir -p $NEW_PROJECT_DIR/site/
|
mkdir -p $NEW_PROJECT_DIR/site/
|
||||||
mkdir -p $NEW_PROJECT_DIR/templates/
|
mkdir -p $NEW_PROJECT_DIR/templates/
|
||||||
echo \
|
echo \
|
||||||
"<?php
|
"<?php
|
||||||
\$site_name = \"$NEW_PROJECT_NAME\";
|
\$site_name = \"$NEW_PROJECT_NAME\";
|
||||||
\$author = \"$ISIDORE_AUTHOR_NAME\";
|
\$site_author = \"$ISIDORE_AUTHOR_NAME\";
|
||||||
|
\$site_url = \"$NEW_PROJECT_URL\";
|
||||||
?>" >> $NEW_PROJECT_DIR/config.php
|
?>" >> $NEW_PROJECT_DIR/config.php
|
||||||
echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version
|
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."
|
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
|
set_config_vars
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
new)
|
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)
|
||||||
clean_project;;
|
clean_project;;
|
||||||
|
help)
|
||||||
|
print_help;;
|
||||||
|
version)
|
||||||
|
echo "$PROJECT_NAME v$ISIDORE_VERSION";;
|
||||||
*)
|
*)
|
||||||
echo "Unknown command $1. Use the 'help' command."
|
echo "Unknown command $1. Use the 'help' command."
|
||||||
print_usage $0;;
|
print_usage
|
||||||
|
exit 1;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user