Compare commits

..

26 Commits

Author SHA1 Message Date
735afe9982 Add new item to ROADMAP for version v0.2.0 2022-11-12 14:55:55 +01:00
6b2bc43d79 Allow choosing port number. 2022-11-10 19:58:46 +01:00
1d1406bb2b Remove unnecessary if-statement. 2022-11-10 19:22:24 +01:00
fc50e669a5 Implement concurrent page compilation. 2022-11-10 19:10:41 +01:00
60c6cb3bcd Consolidate compilation and copy code. 2022-11-10 17:45:00 +01:00
a799374399 Remove need for tmp directory. 2022-11-10 17:07:03 +01:00
281a31f5f7 Remove non-redundant compiling from roadmap.
At least for now this seems to be a bit difficult to implement, due to
dependency testing.
2022-11-09 18:40:22 +01:00
74e2c1a3fd Use local variables. 2022-11-08 16:40:13 +01:00
91b8b3b570 Add verbose flag to build. 2022-11-08 16:10:07 +01:00
e5bbf2dc03 Test for too few commands. 2022-11-08 16:02:38 +01:00
48bdc40932 No source dir to be found anymore. 2022-11-08 15:59:22 +01:00
805139d2ca Add example file. 2022-11-08 15:58:20 +01:00
7c1aec3497 Consolodate project directories into variables. 2022-11-08 15:52:12 +01:00
bfcd194a09 Copy other files into output. 2022-11-08 15:12:29 +01:00
c901bc3b0c Ignore configuration files for PHP variables. 2022-11-07 20:43:19 +01:00
ad5d10979d Add serve command. 2022-11-07 20:26:23 +01:00
76308dc9a9 Add interactive mode to new project subcommand. 2022-11-07 19:50:41 +01:00
d997d829b5 Merge branch 'master' into devel 2022-11-07 19:31:22 +01:00
e0faf6c069 Remove reference to old pages/ directory 2022-11-02 20:45:53 +01:00
8ab0657f29 Add dependency list. 2022-11-02 20:45:14 +01:00
77b8c82a6c Fix XDG_CONFIG_HOME environment variable check. 2022-11-02 16:09:59 +01:00
593b389ccb Add build command. 2022-10-29 15:09:55 +02:00
8f2a2d0c2d Update README. 2022-10-29 14:28:16 +02:00
d3713b6bad Add version command. 2022-10-29 14:24:36 +02:00
44d7def8d4 Add help command. 2022-10-29 14:23:42 +02:00
253ae30746 Add documentation to usage function. 2022-10-29 14:17:30 +02:00
13 changed files with 277 additions and 23 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
output/

View File

@ -3,18 +3,29 @@
A script helping to statically generate websites using a combination of PHP,
HTML, and Markdown.
## Dependencies
- Bash
- PHP
## Usage
Synopsis: `isidore <command> [options]`
Commands:
- `new <dir> <name>`: create a new project directory `<dir>` with project name
`<name>`.
- `build`: build the website (default).
- `new [args] <dir>`: create a new project.
- `<dir>`: new project directory.
- `-i`: interactive mode.
- `build [args]`: build the website.
- `-j<n>`: number of jobs to run concurrently. With `0` it compiles all files
at once.
- `-v`: run with verbose output.
- `serve`, `server [args]`: run an HTTP server of the output (default port 8080).
- `-p <port>`: port number to bind server to.
- `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 +34,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.
@ -42,7 +53,7 @@ please take a look at what needs to be done in the [roadmap](/ROADMAP.md), or
check if there are any to-do comments in the code:
```bash
grep -r "TODO" src/
grep "TODO" isidore.sh
```
## License & Copyright

View File

@ -4,7 +4,7 @@
- New project subcommand
- Basic project compilation
- v0.2
- Don't compile already compiled files
- Multi-thread compiling
- Helper functions & variables
- v0.3
- Markdown support

1
example/.isidore-version Normal file
View File

@ -0,0 +1 @@
0.1.0

5
example/config.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$site_name = "New Project";
$site_author = "Nicolás A. Ortega Froysa";
$site_url = "http://example.com/";
?>

View File

@ -0,0 +1,23 @@
<?php
$title = "Blog";
include("templates/header.html.php");
?>
<p>
Welcome to my blog page! Here's a list of my current entries:
</p>
<ul>
<?php
foreach(glob("site/blog/*.cfg.php") as $i)
{
include($i);
$entry_file = substr($i, 4, -8) . '.html';
echo "<li><a href='$entry_file'>$blog_date - $blog_title</a></li>";
}
?>
</ul>
<?php
include("templates/footer.html.php");
?>

View File

@ -0,0 +1,4 @@
<?php
$blog_title = "My First Post";
$blog_date = "2022-11-07";
?>

View File

@ -0,0 +1,9 @@
<?php
include("site/blog/000-first.cfg.php");
$title = $blog_title;
include("templates/header.html.php");
?>
<p>My first blog post.</p>
<?php
include("templates/footer.html.php");
?>

View File

@ -0,0 +1,10 @@
<?php
$title = "Home";
include("templates/header.html.php");
?>
<p>
Hello, World! This is an example page.
</p>
<?php
include("templates/footer.html.php");
?>

View File

@ -0,0 +1 @@
A test file.

View File

@ -0,0 +1,2 @@
</body>
</html>

View File

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title><?= $title ?> | <?= $site_name?></title>
</head>
<body>
<h1><?= $title ?></h1>

View File

@ -23,6 +23,14 @@ ISIDORE_CONFIG_DIR_OPTIONS=(
"$HOME/.isidore")
ISIDORE_AUTHOR_NAME=""
PROG_NAME=$0
PROJECT_NAME="Isidore"
SOURCE_DIR="site/"
OUTPUT_DIR="output/"
TEMPLATE_DIR="templates/"
PROJECT_CONFIG_FILE="config.php"
##
# Create the configuration file. This function is called if it does not already
# exist.
@ -52,7 +60,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 +79,30 @@ 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
build [-v] [-j<n>]
Build the project rooted in the current directory
serve | server [-p <port>]
Serve a local HTTP server of the output directory
clean
Clean the built files
version
Print the current version
help
Show this help information"
}
##
@ -81,7 +110,7 @@ function print_usage()
##
function check_in_project()
{
if ! [ -f "./config.php" ] || ! [ -f "./.isidore-version" ]
if ! [ -f "$PROJECT_CONFIG_FILE" ] || ! [ -f "./.isidore-version" ]
then
echo "ERROR: You are not currently in the root of an Isidore project."
exit 1
@ -93,21 +122,36 @@ function check_in_project()
#
# Params:
# $1 - The project directory
# $2 - The project name
# $2 - Interactive mode (1 = true; 0 = false)
##
function new_project()
{
NEW_PROJECT_DIR=$1
NEW_PROJECT_NAME=$2
echo "$PROJECT_NAME v$ISIDORE_VERSION"
local NEW_PROJECT_DIR=$1
local NEW_PROJECT_NAME="New Project"
local 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/
mkdir -p $NEW_PROJECT_DIR/$SOURCE_DIR
mkdir -p $NEW_PROJECT_DIR/$TEMPLATE_DIR
echo \
"<?php
\$site_name = \"$NEW_PROJECT_NAME\";
\$author = \"$ISIDORE_AUTHOR_NAME\";
?>" >> $NEW_PROJECT_DIR/config.php
\$site_author = \"$ISIDORE_AUTHOR_NAME\";
\$site_url = \"$NEW_PROJECT_URL\";
?>" >> $NEW_PROJECT_DIR/$PROJECT_CONFIG_FILE
echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version
echo "New project created."
[ $2 == 0 ] &&
echo "Consider taking a look at the $NEW_PROJECT_DIR/$PROJECT_CONFIG_FILE file."
}
##
@ -116,21 +160,157 @@ function new_project()
function clean_project()
{
check_in_project
if [ -d "./output/" ]
if [ -d "$OUTPUT_DIR" ]
then
rm -r ./output/
rm -r $OUTPUT_DIR
fi
echo "Project cleaned."
}
##
# Build the project.
#
# Params:
# $1 - Verbose flag
# $2 - Maximum number of jobs to run
##
function build_project()
{
check_in_project
mkdir -p $OUTPUT_DIR
for i in $(find $SOURCE_DIR -type d)
do
mkdir -p $OUTPUT_DIR/${i:${#SOURCE_DIR}}
done
# number of current jobs
local NUM_JOBS="\j"
for i in $(find site -type f -regextype posix-extended -not -regex '.*\.(cfg|CFG)\.(php|PHP)')
do
while (( $2 != 0 )) && (( ${NUM_JOBS@P} >= $2 ))
do
wait -n
done
# parallel block
(
if [[ $i =~ .*\.(php|PHP) ]]
then
: ${i:${#SOURCE_DIR}}
local OUT_FILE="$OUTPUT_DIR/${_: :-4}"
if [ $1 == 1 ]
then
echo "Building $OUT_FILE ..."
fi
cat $PROJECT_CONFIG_FILE $i | php > $OUT_FILE
else
local OUT_FILE="$OUTPUT_DIR/${i:${#SOURCE_DIR}}"
if [ $1 == 1 ]
then
echo "Copying $OUT_FILE ..."
fi
cp $i $OUT_FILE
fi
) &
done
# wait for jobs to finish
wait -n
}
set_config_vars
if [ $# -lt 1 ]
then
echo "No subcommand was specified. Use the 'help' subcommand."
print_usage
exit 1
fi
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' subcommand."
print_usage
exit 1
fi;;
esac
done
new_project $NEW_DIR $INTERACTIVE;;
build)
VERBOSE=0
JOBS=1
for i in ${@:2}
do
case $i in
-v)
VERBOSE=1;;
-j*)
if ! [[ "$i" =~ ^-j[0-9]+$ ]]
then
echo "Argument '$i' badly formatted. Should be '-j<n>' where <n> is a number."
print_usage
exit 1
fi
JOBS=${i:2};;
*)
echo "Unknown argument for build '$i'. Use the 'help' subcommand."
print_usage
exit 1;;
esac
done
build_project $VERBOSE $JOBS;;
serve|server)
PORT=8080
shift
while getopts "p:" opt
do
case $opt in
p)
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]]
then
echo "Invalid port $OPTARG. Please enter a number."
exit 1
fi
PORT=$OPTARG;;
?)
echo "Invalid argument $OPTARG. Use the 'help' subcommand."
print_usage
exit 1;;
:)
echo "Option -$OPTARG requires an argument."
exit 1;;
esac
done
php -S localhost:$PORT -t $OUTPUT_DIR/;;
clean)
clean_project;;
help)
print_help;;
version)
echo "$PROJECT_NAME v$ISIDORE_VERSION";;
*)
echo "Unknown command $1. Use the 'help' command."
print_usage $0;;
echo "Unknown command $1. Use the 'help' subcommand."
print_usage
exit 1;;
esac