Compare commits
18 Commits
b06f2b1a1c
...
v0.1.0
Author | SHA1 | Date | |
---|---|---|---|
91b8b3b570 | |||
e5bbf2dc03 | |||
48bdc40932 | |||
805139d2ca | |||
7c1aec3497 | |||
bfcd194a09 | |||
c901bc3b0c | |||
ad5d10979d | |||
76308dc9a9 | |||
d997d829b5 | |||
e0faf6c069 | |||
8ab0657f29 | |||
77b8c82a6c | |||
593b389ccb | |||
8f2a2d0c2d | |||
d3713b6bad | |||
44d7def8d4 | |||
253ae30746 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
output/
|
20
README.md
20
README.md
@ -3,18 +3,24 @@
|
|||||||
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]`
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
- `new <dir> <name>`: create a new project directory `<dir>` with project name
|
- `new [-i] <dir>`: create a new project directory `<dir>`. Use `-i` for
|
||||||
`<name>`.
|
interactive mode.
|
||||||
- `build`: build the website (default).
|
- `build [-v]`: build the website (default). Use `-v` for verbose.
|
||||||
|
- `serve`, `server`: run an HTTP server of the output on port 8080.
|
||||||
- `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 +29,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.
|
||||||
@ -42,7 +48,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:
|
check if there are any to-do comments in the code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
grep -r "TODO" src/
|
grep "TODO" isidore.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## License & Copyright
|
## License & Copyright
|
||||||
|
1
example/.isidore-version
Normal file
1
example/.isidore-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.1.0
|
5
example/config.php
Normal file
5
example/config.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
$site_name = "New Project";
|
||||||
|
$site_author = "Nicolás A. Ortega Froysa";
|
||||||
|
$site_url = "http://example.com/";
|
||||||
|
?>
|
23
example/site/blog.html.php
Normal file
23
example/site/blog.html.php
Normal 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");
|
||||||
|
?>
|
4
example/site/blog/000-first.cfg.php
Normal file
4
example/site/blog/000-first.cfg.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
$blog_title = "My First Post";
|
||||||
|
$blog_date = "2022-11-07";
|
||||||
|
?>
|
9
example/site/blog/000-first.html.php
Normal file
9
example/site/blog/000-first.html.php
Normal 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");
|
||||||
|
?>
|
10
example/site/index.html.php
Normal file
10
example/site/index.html.php
Normal 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");
|
||||||
|
?>
|
1
example/site/static-file.txt
Normal file
1
example/site/static-file.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
A test file.
|
2
example/templates/footer.html.php
Normal file
2
example/templates/footer.html.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
</body>
|
||||||
|
</html>
|
7
example/templates/header.html.php
Normal file
7
example/templates/header.html.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title><?= $title ?> | <?= $site_name?></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1><?= $title ?></h1>
|
170
isidore.sh
170
isidore.sh
@ -23,6 +23,14 @@ ISIDORE_CONFIG_DIR_OPTIONS=(
|
|||||||
"$HOME/.isidore")
|
"$HOME/.isidore")
|
||||||
ISIDORE_AUTHOR_NAME=""
|
ISIDORE_AUTHOR_NAME=""
|
||||||
|
|
||||||
|
PROG_NAME=$0
|
||||||
|
PROJECT_NAME="Isidore"
|
||||||
|
|
||||||
|
SOURCE_DIR="site/"
|
||||||
|
TMP_DIR="/tmp/isidore-workdesk/"
|
||||||
|
OUTPUT_DIR="output/"
|
||||||
|
TEMPLATE_DIR="templates/"
|
||||||
|
|
||||||
##
|
##
|
||||||
# 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 +60,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 +79,30 @@ 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
|
||||||
|
serve | server
|
||||||
|
Serve a local HTTP server of the output directory on port 8080
|
||||||
|
clean
|
||||||
|
Clean the built files
|
||||||
|
version
|
||||||
|
Print the current version
|
||||||
|
help
|
||||||
|
Show this help information"
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -93,21 +122,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/$SOURCE_DIR
|
||||||
mkdir -p $NEW_PROJECT_DIR/templates/
|
mkdir -p $NEW_PROJECT_DIR/$TEMPLATE_DIR
|
||||||
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."
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -116,21 +160,123 @@ function new_project()
|
|||||||
function clean_project()
|
function clean_project()
|
||||||
{
|
{
|
||||||
check_in_project
|
check_in_project
|
||||||
if [ -d "./output/" ]
|
if [ -d "$OUTPUT_DIR" ]
|
||||||
then
|
then
|
||||||
rm -r ./output/
|
rm -r $OUTPUT_DIR
|
||||||
fi
|
fi
|
||||||
echo "Project cleaned."
|
echo "Project cleaned."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##
|
||||||
|
# Build the project.
|
||||||
|
#
|
||||||
|
# Params:
|
||||||
|
# $1 - Verbose flag
|
||||||
|
##
|
||||||
|
function build_project()
|
||||||
|
{
|
||||||
|
check_in_project
|
||||||
|
|
||||||
|
CFG_HEADER_FILE="$TMP_DIR/config-header.php"
|
||||||
|
|
||||||
|
mkdir -p $OUTPUT_DIR
|
||||||
|
mkdir -p $TMP_DIR
|
||||||
|
echo "<?php include(getcwd() . '/config.php'); ?>" > $CFG_HEADER_FILE
|
||||||
|
|
||||||
|
for i in $(find $SOURCE_DIR -type d)
|
||||||
|
do
|
||||||
|
mkdir -p $OUTPUT_DIR/${i:${#SOURCE_DIR}}
|
||||||
|
mkdir -p $TMP_DIR/$i
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in $(find $SOURCE_DIR -name '*.php' -not -name '*.cfg.php')
|
||||||
|
do
|
||||||
|
cat $CFG_HEADER_FILE $i > $TMP_DIR/$i
|
||||||
|
: ${i:${#SOURCE_DIR}}
|
||||||
|
OUT_FILE="$OUTPUT_DIR/${_: :-4}"
|
||||||
|
if [ $1 == 1 ]
|
||||||
|
then
|
||||||
|
echo "Building $OUT_FILE ..."
|
||||||
|
fi
|
||||||
|
php $TMP_DIR/$i > $OUT_FILE
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in $(find $SOURCE_DIR -type f -not -name '*.php')
|
||||||
|
do
|
||||||
|
OUT_FILE="$OUTPUT_DIR/${i:${#SOURCE_DIR}}"
|
||||||
|
if [ $1 == 1 ]
|
||||||
|
then
|
||||||
|
echo "Copying $OUT_FILE ..."
|
||||||
|
fi
|
||||||
|
cp $i $OUT_FILE
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -r $TMP_DIR
|
||||||
|
}
|
||||||
|
|
||||||
set_config_vars
|
set_config_vars
|
||||||
|
|
||||||
|
if [ $# -lt 1 ]
|
||||||
|
then
|
||||||
|
echo "No subcommand was specified. Use the 'help' subcommand."
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
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' subcommand."
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
new_project $NEW_DIR $INTERACTIVE;;
|
||||||
|
build)
|
||||||
|
VERBOSE=0
|
||||||
|
if [ $# -gt 1 ]
|
||||||
|
then
|
||||||
|
for i in ${@:2}
|
||||||
|
do
|
||||||
|
case $i in
|
||||||
|
-v)
|
||||||
|
VERBOSE=1;;
|
||||||
|
*)
|
||||||
|
echo "Unknown argument for build '$i'. Use the 'help' subcommand."
|
||||||
|
print_usage
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
build_project $VERBOSE;;
|
||||||
|
serve|server)
|
||||||
|
php -S localhost:8080 -t $OUTPUT_DIR/;;
|
||||||
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' subcommand."
|
||||||
print_usage $0;;
|
print_usage
|
||||||
|
exit 1;;
|
||||||
esac
|
esac
|
||||||
|
Reference in New Issue
Block a user