hugo-theme-relearn/docs/test-hugo.bat

95 lines
3.4 KiB
Batchfile
Raw Normal View History

@echo off
setlocal enabledelayedexpansion
set hugo_prefix=
set hugo_version=
set hugo_environment=testing
if not "%~1"=="" (
set hugo_prefix=.hugo
set hugo_version=.%1
)
if not exist "content" (
echo No content directory found.
exit /b
)
2025-01-29 23:30:53 +01:00
rem Relearn theme docs & exampleSite
set "themeDir=.."
if not exist "%themeDir%\layouts\partials\version.txt" (
rem other sites stored parallel to Relearn themes directory
set "themeDir=..\hugo-theme-relearn"
)
if not exist "%themeDir%\layouts\partials\version.txt" (
rem other sites stored inside of repos directory parallel to Relearn theme directory
set "themeDir=..\..\hugo-theme-relearn"
)
if not exist "%themeDir%\layouts\partials\version.txt" (
rem regular theme users
set "themeDir=themes\hugo-theme-relearn"
)
if not exist "%themeDir%\layouts\partials\version.txt" (
rem theme users with custom theme name
set "themeDir=themes\relearn"
)
if not exist "%themeDir%\layouts\partials\version.txt" (
echo Relearn theme not found.
exit /b
)
2025-01-29 23:30:53 +01:00
set "configDir="
if "%hugo_environment%"=="" (
rem No environment given, which is fine
) else if exist "%themeDir%\docs\config\%hugo_environment%\hugo.toml" (
rem New themes docs
set "configDir=%themeDir%\docs\config\%hugo_environment%"
) else if exist "%themeDir%\exampleSite\config\%hugo_environment%\hugo.toml" (
rem Old themes docs inside of exampleSite
set "configDir=%themeDir%\exampleSite\config\%hugo_environment%"
) else (
echo Environment configuration %hugo_environment% not found.
exit /b
)
set "config="
if "%hugo_environment%"=="" (
rem No environment given, which is fine
) else if exist "config\%hugo_environment%" (
2025-01-29 23:30:53 +01:00
rem seems we are in the themes docs, no need to copy anything
set config=--environment %hugo_environment%
) else if exist "config.toml" (
set config=--config config.toml,%configDir%\hugo.toml
) else if exist "hugo.toml" (
set config=--config hugo.toml,%configDir%\hugo.toml
) else if exist "config" (
copy /e /i /y "%configDir%" "config\%hugo_environment%"
set config=--environment %hugo_environment%
) else if exist "hugo" (
copy /e /i /y "%configDir%" "hugo\%hugo_environment%"
set config=--environment %hugo_environment%
) else (
echo Environment configuration can not be applied.
exit /b
)
set /p version=<"%themeDir%\layouts\partials\version.txt"
set "version=.!version!"
echo %version%>"metrics%version%%hugo_prefix%%hugo_version%.log"
echo on
2025-01-20 07:47:26 +01:00
hugo%hugo_version% %config% --printPathWarnings --printI18nWarnings --templateMetrics --templateMetricsHints --cleanDestinationDir --logLevel info --destination "public%version%%hugo_prefix%%hugo_version%" >> "metrics%version%%hugo_prefix%%hugo_version%.log" 2>&1
@echo off
set "start_dir=%CD%\public%version%%hugo_prefix%%hugo_version%"
set "output_file=dir%version%%hugo_prefix%%hugo_version%.log"
if exist "%output_file%" del "%output_file%"
for /r "%start_dir%" %%F in (*) do (
set "file=%%F"
echo !file:%start_dir%\=! >> "%output_file%"
)
move /Y "dir%version%%hugo_prefix%%hugo_version%.log" "public%version%%hugo_prefix%%hugo_version%\dir.log" 2>&1 >NUL
move /Y "metrics%version%%hugo_prefix%%hugo_version%.log" "public%version%%hugo_prefix%%hugo_version%\metrics.log" 2>&1 >NUL
for /F "UseBackQ Delims==" %%A In ("public%version%%hugo_prefix%%hugo_version%\metrics.log") do Set "lastline=%%A"
echo %lastline%