Created
May 23, 2024 15:14
-
-
Save krzemienski/35bd83b2f5b9881623f831f34bd18c84 to your computer and use it in GitHub Desktop.
A shell script to test out multiple static site generators for awesome lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to check if a port is available | |
check_port() { | |
local port=$1 | |
if ! lsof -i:$port > /dev/null; then | |
echo $port | |
else | |
while lsof -i:$port > /dev/null; do | |
port=$((port+1)) | |
done | |
echo $port | |
fi | |
} | |
# Ensure required tools are installed | |
install_dependencies() { | |
echo "Installing necessary dependencies..." | |
# Install pip if not installed | |
if ! command -v pip &> /dev/null; then | |
echo "pip not found. Installing pip..." | |
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | |
python get-pip.py | |
rm get-pip.py | |
fi | |
# Install mkdocs | |
if ! command -v mkdocs &> /dev/null; then | |
echo "mkdocs not found. Installing mkdocs..." | |
pip install mkdocs | |
fi | |
# Install hugo | |
if ! command -v hugo &> /dev/null; then | |
echo "hugo not found. Installing hugo..." | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
brew install hugo | |
else | |
sudo snap install hugo | |
fi | |
fi | |
# Install yarn if not installed | |
if ! command -v yarn &> /dev/null; then | |
echo "yarn not found. Installing yarn..." | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
brew install yarn | |
else | |
npm install -g yarn | |
fi | |
fi | |
# Install docsify-cli | |
if ! command -v docsify &> /dev/null; then | |
echo "docsify not found. Installing docsify..." | |
npm install -g docsify-cli | |
fi | |
echo "All dependencies are installed." | |
} | |
# Parse the title from README.md | |
parse_title() { | |
TITLE=$(grep -m 1 '^# ' $README_FILE | sed 's/^# //') | |
echo "Parsed title: $TITLE" | |
} | |
# Function to set up MkDocs | |
setup_mkdocs() { | |
local dir="$1/mkdocs-site" | |
local port=$2 | |
mkdir -p $dir | |
cd $dir | |
mkdocs new . | |
mv $README_FILE docs/index.md | |
sed -i "s/site_name:.*/site_name: $TITLE/" mkdocs.yml | |
mkdocs build | |
mkdocs serve -a 127.0.0.1:$port & | |
cd - > /dev/null | |
} | |
# Function to set up Hugo | |
setup_hugo() { | |
local dir="$1/hugo-site" | |
local port=$2 | |
mkdir -p $dir | |
cd $dir | |
hugo new site . | |
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke | |
echo 'theme = "ananke"' >> config.toml | |
echo "title = \"$TITLE\"" >> config.toml | |
cp $README_FILE content/_index.md | |
hugo | |
hugo server -D -p $port & | |
cd - > /dev/null | |
} | |
# Function to set up VuePress | |
setup_vuepress() { | |
local dir="$1/vuepress-site" | |
local port=$2 | |
mkdir -p $dir/docs | |
cd $dir | |
yarn add -D vuepress | |
echo "module.exports = { title: \"$TITLE\", description: \"An Awesome List\" }" > docs/.vuepress/config.js | |
cp $README_FILE docs/README.md | |
npx vuepress build docs | |
npx vuepress dev docs --port $port & | |
cd - > /dev/null | |
} | |
# Function to set up Docsify | |
setup_docsify() { | |
local dir="$1/docsify-site" | |
local port=$2 | |
mkdir -p $dir | |
cd $dir | |
echo "<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=\"UTF-8\"> | |
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> | |
<title>$TITLE</title> | |
<link rel=\"stylesheet\" href=\"//cdn.jsdelivr.net/npm/docsify/lib/themes/vue.css\"> | |
</head> | |
<body> | |
<div id=\"app\"></div> | |
<script> | |
window.\$docsify = { | |
name: \"$TITLE\", | |
repo: \"\", | |
loadSidebar: true, | |
subMaxLevel: 2, | |
} | |
</script> | |
<script src=\"//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js\"></script> | |
</body> | |
</html>" > index.html | |
cp $README_FILE . | |
docsify serve --port $port & | |
cd - > /dev/null | |
} | |
# Check if the correct number of arguments is provided | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 README_FILE OUTPUT_DIRECTORY" | |
exit 1 | |
fi | |
# Assign arguments to variables | |
README_FILE=$1 | |
OUTPUT_DIR=$2 | |
# Parse the title from the README file | |
parse_title | |
# Create the main directory | |
mkdir -p $OUTPUT_DIR | |
# Install dependencies | |
install_dependencies | |
# Find available ports | |
MKDOCS_PORT=$(check_port 8001) | |
HUGO_PORT=$(check_port 8002) | |
VUEPRESS_PORT=$(check_port 8003) | |
DOCSIFY_PORT=$(check_port 8004) | |
# Set up each framework | |
setup_mkdocs $OUTPUT_DIR $MKDOCS_PORT | |
setup_hugo $OUTPUT_DIR $HUGO_PORT | |
setup_vuepress $OUTPUT_DIR $VUEPRESS_PORT | |
setup_docsify $OUTPUT_DIR $DOCSIFY_PORT | |
echo "Setup completed. You can now preview each framework by navigating to the respective URLs." | |
echo "MkDocs: http://127.0.0.1:$MKDOCS_PORT" | |
echo "Hugo: http://127.0.0.1:$HUGO_PORT" | |
echo "VuePress: http://127.0.0.1:$VUEPRESS_PORT" | |
echo "Docsify: http://127.0.0.1:$DOCSIFY_PORT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment