Skip to content

Commit

Permalink
Scripts updated with prompt for build type
Browse files Browse the repository at this point in the history
- Since it appears Jekyll's `--incremental` build type never rebuilds the search index, which means search results and sidebar section tree don't sync with any changes that affect eg. permalinks when testing locally (doesn't affect Github's full build).
  • Loading branch information
chocmake authored Apr 6, 2024
1 parent 6421837 commit 873d51e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 15 deletions.
70 changes: 61 additions & 9 deletions run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,69 @@ setlocal enableextensions enabledelayedexpansion
set "scriptname=[%~n0.bat]"
title MGSV Wiki ^| Run local server

:: Build options
set "inctext[1]=incremental builds"
set "inctext[2]=full builds"

echo Options for this session: & echo.
echo [1] / [Enter] Use !inctext[1]! (default)
echo [2] Use !inctext[2]!

echo. & <nul set /p "=Select desired option: "
call :choice "12"
call :incremental !errorlevel!

:: Set expected environment variable for bundle so it knows where the Gemfile is located
set "BUNDLE_GEMFILE=.env-files/Gemfile.github"

:: Generate the site (also use 'live reload' so any file change in repo will automatically re-generate site)
bundle exec jekyll serve --host localhost --force_polling --livereload --incremental
bundle exec jekyll serve --host localhost --force_polling --livereload !incremental!
if !errorlevel! equ 0 (
exit
) else (
echo. & echo !scriptname! Error encountered. Exit code: !errorlevel! & echo.
rem Custom pause prompt text to use 'exit' instead of 'continue' wording
pause >nul|set /p "=!scriptname! Press any key to exit... " & exit
)

exit /b
exit
) else (
echo. & echo !scriptname! Error encountered. Exit code: !errorlevel! & echo.
rem Custom pause prompt text to use 'exit' instead of 'continue' wording
pause >nul|set /p "=!scriptname! Press any key to exit... " & exit
)

exit /b

:: Calls
:choice
setlocal disabledelayedexpansion
set "n=0" & set "c=" & set "e=" & set "map=%~1"
if not defined map endlocal & exit /b 0
for /f "eol=1 delims=" %%i in ('xcopy /lwq "%~f0" :\') do set "c=%%i" & rem detect and store input
set "c=%c:~-1%" & rem obtain last character
if defined c (
for /f delims^=^ eol^= %%i in ('cmd /von /u /c "echo(!map!"^|find /v ""^|findstr .') do (
set /a "n += 1" & set "e=%%i"
setlocal enabledelayedexpansion
if /i "!e!"=="!c!" (
echo(!c!
for /f %%j in ("!n!") do endlocal & endlocal & exit /b %%j
)
endlocal
)
) else (
rem If Enter pressed
echo(default selected
endlocal
exit /b 99
)
endlocal & goto :choice
exit /b

:incdefault
set "inctext=!inctext[1]!"
set "incremental=--incremental"
exit /b

:incremental
set "inctext=!inctext[%1]!"
if %1 equ 1 call :incdefault
if %1 equ 99 call :incdefault
cls & echo !scriptname! Selected: !inctext!. Starting build and server... & echo.
exit /b

endlocal
57 changes: 56 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,62 @@
#!/usr/bin/env bash

choice () {
while true; do
read -rsn1 -p "${prompt}" input
if [ "$input" = "" ]; then
# If Enter/space pressed
return "99"
elif [[ "${choices[@]}" =~ "${input}" ]]; then
# Convert order in array to integer for exit code
for i in "${!choices[@]}"; do
if [[ "${choices[$i]}" = "${input}" ]]; then
return "$((${i}+1))";
fi
done
else
resetline "${#prompt}"
choice
fi
return "$?"
break
done
}

resetline () {
# ANSI escape sequence to set cursor at start of line
echo -en "\033[${1}D"
}

incremental () {
local text="${inc_text[${1}]}"

if [[ "${1}" == "1" || "${1}" == "99" ]]; then
text="${inc_text[1]}"
incremental="--incremental"
fi

resetline "${#prompt}"
echo "${script_name} Selected: ${text}. Starting build and server..."
echo
}

script_name="[`basename $0`]"
inc_text[1]="incremental builds"
inc_text[2]="full builds"

echo "Options for this session:"
echo
echo " [1] / [Enter] Use ${inc_text[1]} (default)"
echo " [2] Use ${inc_text[2]}"
echo

prompt="Select desired option: "
choices=("1" "2")
choice
incremental "$?"

# Set expected environment variable for bundle so it knows where the Gemfile is located
export BUNDLE_GEMFILE=".env-files/Gemfile.github"

# Generate the site (also use 'live reload' so any file change in repo will automatically re-generate site)
bundle exec jekyll serve --host localhost --force_polling --livereload --incremental
bundle exec jekyll serve --host localhost --force_polling --livereload "${incremental}"
10 changes: 5 additions & 5 deletions wiki/Meta/Running_a_Local_Server/Running_a_Local_Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ Now we're ready to run the server. Any time you'd like to run it just do the fol

1. In the root directory of your fork double-click the `run.bat` script. This will build the wiki then run a web server locally on Windows that can be accessed via a browser.
> The server is only accessible on your system, not over the internet.
2. Minimize the CMD window and launch a browser.
3. Enter `localhost:4000` in the addressbar to visit the local wiki running on your system!
2. The script will prompt for whether you'd like to use incremental or full builds for the current session. Press `1` or `Enter` key for the incremental build type (faster).
> The alternative full build option will rebuild the whole wiki any time a change is detected. This is useful if you've changed some permalink metadata and need the search results and sidebar [sections](/Meta/Creating_Editing_Pages/Metadata_Organization/Creating_a_Section) to sync up with the changes.
3. Minimize the CMD window and launch a browser.
4. Enter `localhost:4000` in the addressbar to visit the local wiki running on your system!

> You'll notice a new `_site` directory in the root of the wiki directory appear. This directory only contains the compiled versions of pages/files for the local server and is ignored by Github Desktop when detecting file changes, so avoid editing any of the files within.
### Closing the local server

You can stop the local server running at any time by opening the CMD window you minimized and pressing `Ctrl+C` (the 'cancel' command) then confirming the two prompts by pressing `y` and `Enter`.
You can stop the local server running at any time by opening the CMD window you minimized and pressing `Ctrl+C` (the 'cancel' command) twice to terminate the process.

## Making changes

Expand All @@ -68,7 +70,5 @@ You can then submit your changes back to the original wiki as per the [Github De

> **Note:** it takes a moment to rebuild for each change so there'll be a delay between the change(s) and when they'll appear. The changes should automatically appear in the browser without requiring a refresh, once they've been built and are ready.
> **Note:** certain changes that affect 'includes' like category auto indexes may not be detected with the default incremental buiild (since incremental builds only update the page/files that have been detected as modified). In such a case you can close the local server via CMD then re-run the `run.bat` which will build the entire site again.
> **Tip:** you can check what's happening by viewing the CMD window while the local server is running.

0 comments on commit 873d51e

Please sign in to comment.