Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 177 additions & 106 deletions arise
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash

# https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Comment on lines +3 to +4
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason you modified this and moved it up here is to allow a config option to make it easier to overwrite To make this cleaner, I changed it to an optional item; see additional suggestion below to use the snippet by default but allow overwrite.

Since PR base branch changes aren't disabled and GitHub reviews won't let me comment on the entire file, can I ask that you move this option below the version tag stub but above the 'begin main function' stub?

Suggested change
# https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# If you want to manually specify the path to the arise binary, you can uncomment and modify the variable below.
# This should not be necessary in most cases and this should generally be left as default.
# SCRIPT_DIR="/change/this/to/path/to/arise"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I added this is because the script(s) is very reliant on relative paths to the root of the arise folder. My rationale is that it doesn't hurt to begin with a cd to the directory of the arise (and I get the path via this line) instead of relying on the user or external factors to have the appropriate current directory.

The reason this is at the top of the file is because that stackoverflow answer that I always copy paste in such situation says to be aware that this must be done before cd-ing to any other directory, so i paste it on the first lines.


######################################
# ARISE
# https://github.com/spectrasecure/arise
Expand All @@ -10,14 +14,28 @@ arise_version="1.1.0"
# Don't edit below this line unless you know what you're doing
##############################################################

cd "$(dirname $0)"
cd "$SCRIPT_DIR"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the default as an option so that a user can change the SCRIPT_DIR if they want to above; otherwise they leave it unset and it uses the default.

Suggested change
cd "$SCRIPT_DIR"
# Default to the script's directory if SCRIPT_DIR is not set
# https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
SCRIPT_DIR_DEFAULT=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Check if SCRIPT_DIR is set and non-empty using parameter expansion; otherwise use SCRIPT_DIR_DEFAULT
cd "${SCRIPT_DIR:-$SCRIPT_DIR_DEFAULT}" || {
echo "Error: Unable to change directory to '${SCRIPT_DIR:-$SCRIPT_DIR_DEFAULT}'"
exit 1
}

Copy link
Copy Markdown
Author

@HerissonMignion HerissonMignion Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's nice for the moment (and the forseable future?) that arise is small enough that it comes with the website that it builds, kind of like the way the gnu autotools are "installed" in the project they compile (but without the complexity of gnu autohell autotools). (EDIT: And therefore I dont see the point of making this configurable.)

But if you insist, I'll do as you say.



# Set the site config directories. Don't touch this-- changing the config location is not supported at this time
config="arise-out/config"
source arise-source/config/arise.conf

# Check if we're running a current version of bash before potentially causing code that won't run properly on ancient bash versions
[ "$BASH_VERSINFO" -lt 5 ] && echo -e 'ERROR: Arise requires Bash version 5 or greater to run. Please install a newer version of Bash or ensure that you are using the newest version installed on your computer.\n\nYour current version of Bash is: '"$BASH_VERSINFO"'\n\nYou can verify the current running version of Bash by running the following command: echo "$BASH_VERSINFO"' && exit 1
if [ "$BASH_VERSINFO" -lt 5 ]; then
cat <<ERROR >&2
ERROR: Arise requires Bash version 5 or greater to run. Please install
a newer version of Bash or ensure that you are using the newest
version installed on your computer.

Your current version of Bash is: $BASH_VERSINFO

You can verify the current running version of Bash by running the
following command: echo "\$BASH_VERSINFO"

ERROR
exit 1
fi

# Makes sure that our paths have or don't have a '/' as expected regardless of user input.
## Favicon should have a '/' at the start of the path.
Expand All @@ -26,134 +44,187 @@ source arise-source/config/arise.conf
[[ ${base_url: -1} == '/' ]] && base_url=${base_url::-1}

# Source functions
for FILE in lib/functions/inline/* ; do [[ $FILE == *.sh ]] && source $FILE ; done
for FILE in lib/functions/subshell/* ; do [[ $FILE == *.sh ]] && source $FILE ; done
for FILE in lib/functions/{subshell,inline}/*.sh; do
source "$FILE"
done




# Display our pretty logo no matter what when the program is run :)
arise_logo

# Set default build settings
force_overwrite=false
keep_source=false

# Read our arguments and set the build mode for processing. Display help if an invalid option is made.
if [[ $@ == "build" ]]; then
arise_build="full"
echo "Starting site deploy. Building full site."
elif [[ $@ == "build -k" ]]; then
arise_build="full"
keep_source=true
echo "Starting site deploy. Building full site. Source .md files will be retained in the final output."
elif [[ $@ == "build -f" ]]; then
arise_build="full"
echo "Starting site deploy. Building full site."
echo;
read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r;
echo;
if [[ $REPLY =~ ^[Yy]$ ]]; then
force_overwrite=true;
else
echo 'Aborting.';
exit 1;
fi;
elif [[ $@ == "build -kf" ]] || [[ $@ == "build -fk" ]]; then
arise_build="full"
keep_source=true
echo "Starting site deploy. Building full site. Source .md files will be retained in the final output."
echo;
read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r;
echo;
if [[ $REPLY =~ ^[Yy]$ ]]; then
force_overwrite=true;
else
echo 'Aborting.';
exit 1;
fi;
else
while getopts ":psrkf" options; do
case "${options}" in
p)
[[ -n "$arise_build" ]] && { arise_help; echo -e '\n\nERROR: Multiple exclusive build options detected. Aborting.'; exit 1; }
arise_build="pages_only";
echo "Starting site deploy. Building pages only.";
;;
s)
[[ -n "$arise_build" ]] && { arise_help; echo -e '\n\nERROR: Multiple exclusive build options detected. Aborting.'; exit 1; }
arise_build="sitemap_only";
echo "Starting site deploy. Building sitemap only.";
;;
r)
[[ -n "$arise_build" ]] && { arise_help; echo -e '\n\nERROR: Multiple exclusive build options detected. Aborting.'; exit 1; }
arise_build="rss_only";
echo "Starting site deploy. Building RSS feed only.";
;;
k)
keep_source=true;
echo "Source .md files will be retained in the final output."l
;;
f)
echo;
read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r;
echo;
if [[ $REPLY =~ ^[Yy]$ ]]; then
force_overwrite=true;
else
echo 'Aborting.';
exit 1;
fi;
;;
esac
done
force_overwrite=0
keep_source=0

build_pages=0
build_sitemap=0
build_rss=0


# first pass to separate options (-asdf becomes -a -s -d -f)
trailing_args=()
while (($#)); do
arg=$1
shift
case "$arg" in
(--?*)
trailing_args+=("$arg")
;;
(--)
trailing_args+=(--)
break
;;
(-*)
for letter in $(echo "${arg#-}" | grep -o .); do
trailing_args+=("-$letter")
done
;;
(*)
trailing_args+=("$arg")
;;
esac
done
set -- "${trailing_args[@]}" "$@"

trailing_args=()
while (($#)); do
arg="$1"
shift
case "$arg" in
(-h|--help)
arise_help
exit 0
;;
(-p|--pages)
build_pages=1
;;
(-s|--sitemap)
build_sitemap=1
;;
(-r|--rss)
build_rss=1
;;
(-f|--force)
force_overwrite=1
;;
(-k|--keep-source)
keep_source=1
;;
(--)
break
;;
(-*)
echo "Unknown option: $arg" >&2
exit 1
;;
(*)
trailing_args+=("$arg")
;;
esac
done
set -- "${trailing_args[@]}" "$@"


# Display help if no arguments are provided
if [ "$#" -eq 0 ]; then
arise_help
exit 0
fi

[[ -z "$arise_build" ]] && { arise_help; exit 1; }
# Ensure first non-option argument is 'build' for default behaviour. Shift arguments and continue.
if [ "$1" != "build" ]; then
arise_help
exit 1
fi
shift



if ! (($build_pages || $build_sitemap || $build_rss)); then
build_pages=1
build_sitemap=1
build_rss=1
fi


echo


if (($force_overwrite)); then
read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r
echo
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo 'Aborting.'
exit 1
fi
fi

# Make sure "arise_out" is empty and copy the source files over there to work from during the build process.
[[ -d arise-out ]] && [[ "$force_overwrite" == true ]] && rm -rf arise-out
[[ -d arise-out ]] && (($force_overwrite)) && rm -rf arise-out
mkdir -p arise-out
[[ -n "$(ls -A arise-out)" ]] && echo -e 'ERROR: The build output directory "/arise-out" is not empty. Program aborted to prevent overwrite of existing data.\n\nPlease empty the output directory before running Arise again or run your command with the "-f" flag to overwrite the existing output (dangerous).' && exit 1
if [[ -n "$(ls -A arise-out)" ]]; then
cat <<"ERROR" >&2
ERROR: The build output directory "/arise-out" is not empty. Program
aborted to prevent overwrite of existing data.

Please empty the output directory before running Arise again or run
your command with the "-f" flag to overwrite the existing output
(dangerous).
ERROR
exit 1
fi
cp -r "arise-source/". "arise-out"
## Set an absolute path for $config
config=$(realpath $config)
config=$(realpath "$config")

# Define a temporary file for a list of all source files for post-build cleanup
removelist="arise-out/arise-remove-$RANDOM.tmp"
touch $removelist
removelist=$(realpath $removelist)
removelist=$(realpath "$removelist")
touch "$removelist"

# Run the build process depending on whatever options have been set
if [[ "$arise_build" == "full" ]] || [[ "$arise_build" == "pages_only" ]]; then
echo -n "Building pages..."
build_page_tree arise-out || { echo "ERROR: An error was encountered while building pages. Aborting build cycle."; exit 1; }
echo " DONE."
if (($build_pages)); then
echo -n "Building pages..."
build_page_tree arise-out || {
echo "ERROR: An error was encountered while building pages. Aborting build cycle." >&2
exit 1
}
echo " DONE."
fi

if [[ "$arise_build" == "full" ]] || [[ "$arise_build" == "rss_only" ]]; then
echo -n "Building RSS feed..."
build_rss arise-out/rss.xml || { echo "ERROR: An error was encountered while building the RSS feed. Aborting build cycle."; exit 1; }
echo " DONE."
if (($build_rss)); then
echo -n "Building RSS feed..."
build_rss arise-out/rss.xml || {
echo "ERROR: An error was encountered while building the RSS feed. Aborting build cycle." >&2
exit 1
}
echo " DONE."
fi

if [[ "$arise_build" == "full" ]] || [[ "$arise_build" == "sitemap_only" ]]; then
echo -n "Building sitemap..."
build_sitemap arise-out/sitemap.xml || { echo "ERROR: An error was encountered while building the sitemap. Aborting build cycle."; exit 1; }
echo " DONE."
if (($build_sitemap)); then
echo -n "Building sitemap..."
build_sitemap arise-out/sitemap.xml || {
echo "ERROR: An error was encountered while building the sitemap. Aborting build cycle." >&2
exit 1
}
echo " DONE."
fi

if [[ "$keep_source" == false ]]; then
echo -n "Cleaning up build source files from output..."
# Remove every page that we built from as part of the build cycle
while read fname; do
[[ -f "$fname" ]] && rm "$fname"
done <$removelist
# Remove site config templates
rm "$config/header.html"
rm "$config/content_header.html"
rm "$config/footer.html"
rm "$config/arise.conf"
echo " DONE."
if ! (($keep_source)); then
echo -n "Cleaning up build source files from output..."
# Remove every page that we built from as part of the build cycle
while IFS="" read -r fname; do
[[ -f "$fname" ]] && rm "$fname"
done < "$removelist"
# Remove site config templates
rm "$config/header.html"
rm "$config/content_header.html"
rm "$config/footer.html"
rm "$config/arise.conf"
echo " DONE."
fi

rm $removelist
rm "$removelist"
echo -e '\nBuild completed! Built artefacts have been generated at:\n'"$(realpath arise-out)"
14 changes: 7 additions & 7 deletions ci/xml-reserved-characters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo ""
echo ""

echo "Testing to ensure the Arise site built the test suite page..."
if [ -f $testpage ]
if [ -f "$testpage" ]
then
echo "SUCCESS!"
else
Expand All @@ -24,7 +24,7 @@ echo ""

echo "Testing to ensure that the title is rendering as it should..."
titletest="<title>CI Test Suite - XML Reserved Characters &#38; &#60; &#62; &#39; &#34;"
if [[ $(grep "$titletest" $testpage) ]]
if [[ $(grep "$titletest" "$testpage") ]]
then
echo "SUCCESS!"
else
Expand All @@ -34,14 +34,14 @@ else
echo "$titletest"
echo "==========="
echo "Full line that contains a discrepancy:"
echo "$(grep '<title>' $testpage | head -1)"
echo "$(grep '<title>' "$testpage" | head -1)"
exit 1
fi
echo ""

echo "Testing to ensure that the author is rendering as they should..."
authortest='<meta name="author" content="Spectra Secure &#38; &#60; &#62; &#39; &#34;">'
if [[ $(grep "$authortest" $testpage) ]]
if [[ $(grep "$authortest" "$testpage") ]]
then
echo "SUCCESS!"
else
Expand All @@ -51,14 +51,14 @@ else
echo "$authortest"
echo "==========="
echo "Full line that contains a discrepancy:"
echo "$(grep '<meta name="author"' $testpage | head -1)"
echo "$(grep '<meta name="author"' "$testpage" | head -1)"
exit 1
fi
echo ""

echo "Testing to ensure that the description is rendering as it should..."
descriptiontest='<meta name="description" content="This post tests if we are properly filtering XML reserved characters in page metadata &#38; &#60; &#62; &#39; &#34;">'
if [[ $(grep "$descriptiontest" $testpage) ]]
if [[ $(grep "$descriptiontest" "$testpage") ]]
then
echo "SUCCESS!"
else
Expand All @@ -68,6 +68,6 @@ else
echo "$descriptiontest"
echo "==========="
echo "Full line that contains a discrepancy:"
echo "$(grep '<meta name="description"' $testpage | head -1)"
echo "$(grep '<meta name="description"' "$testpage" | head -1)"
exit 1
fi
2 changes: 1 addition & 1 deletion docs/guides/getting-started/cloudflare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ This guide assumes that you have completed steps 1-3 from [Getting Started](../R
10. Click **None** and **Save**.
<p align="center"><img src="cloudflare-2.png" alt="Screenshot: Disable Cloudflare Preview deployments" width=50% height=50% /></p>

As of this writing, if you don't IMMEDIATELY disable preview deployments, Cloudflare will automatically generate live externally-accessible "preview" URLs for every single branch in your website repo (even if your repo is private). Based on how Arise works, this will not only result in previews that are broken and do not work, but it will disclose literally everything in your repo including potentially WIP pages if your repo is private. To put a cherry on top, after preview deployments have been build for a branch, you cannot delete them without deleting and re-adding your entire damn website. What a stupid-ass system.
As of this writing, if you don't IMMEDIATELY disable preview deployments, Cloudflare will automatically generate live externally-accessible "preview" URLs for every single branch in your website repo (even if your repo is private). Based on how Arise works, this will not only result in previews that are broken and do not work, but it will disclose literally everything in your repo including potentially WIP pages if your repo is private. To put a cherry on top, after preview deployments have been build for a branch, you cannot delete them without deleting and re-adding your entire damn website. What a stupid system.

Anyway, rants aside, your site should now be up and running on Cloudflare Pages! Congrats! If you'd like to use a custom domain, please review Cloudflare's [custom domains guide](https://developers.cloudflare.com/pages/platform/custom-domains/) as that is outside of the scope of this documentation.
Loading