Skip to content

Commit

Permalink
Move the HTML file update loop into REXX
Browse files Browse the repository at this point in the history
Its faster and cleaner. Also get rid of the dry-run option - its not useful.
  • Loading branch information
davidrg committed Nov 28, 2024
1 parent 124bb96 commit 0dbe2c5
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,7 @@ jobs:
- name: Prepare Documentation
run: |
set root=${{ github.workspace }}
mkdocs.bat /W /D
call mkdocs.bat /W /D
shell: cmd
working-directory: ${{ github.workspace }}\doc
- name: Upload artifact
Expand Down
35 changes: 19 additions & 16 deletions doc/mkdocs.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if [%1] == [--help] goto :help
REM Defaults: use git dates, build for K95 distribution (not web) with https
REM links.
set GIT_DATES=true
set DRY_RUN=false
set DEV_MODE=false
set WEB_MODE=false
set HTTPS_MODE=true
Expand All @@ -21,7 +20,7 @@ for %%I in (%*) do (
rem Value after a switch
if defined switch (

rem Example: /X
rem /O for Output Directory
if /i "!switch:~1!"=="O" set "OUT_DIR=%%~I"

set "switch="
Expand All @@ -32,13 +31,12 @@ for %%I in (%*) do (
echo(%%~I | >NUL findstr "^[-/]" && (
set "switch=%%~I"
REM G = no git-file-dates
REM N = dry-run
REM D = dev-mode
REM W = web-mode
REM S = use-https

rem Check for a valid switch
for %%x in (G N D W I O) do (
for %%x in (G D W I O) do (
if /i "!switch:~1!"=="%%x" set "valid=true"
)

Expand All @@ -54,11 +52,6 @@ for %%I in (%*) do (
set "switch="
)

if /i "!switch:~1!"=="N" (
set "DRY_RUN=true"
set "switch="
)

if /i "!switch:~1!"=="D" (
set "DEV_MODE=true"
set "switch="
Expand Down Expand Up @@ -91,7 +84,6 @@ echo libraries must also be built and avaialble.
echo.
echo Options:
echo /G Don't get file dates from git. Timestamps will be wrong.
echo /N Dry run - don't actually do anything
echo /D Dev mode - release tag will be "DEV" rather than "BETA.7" or
echo nothing, indicating this isn't an final/release version of the
echo manual.
Expand Down Expand Up @@ -122,7 +114,6 @@ if "%OUT_DIR%" == "" set OUT_DIR=%dist_root%\docs\manual\

echo Parameters:
echo Git File dates: %GIT_DATES%
echo Dry Run: %DRY_RUN%
echo Dev Mode: %DEV_MODE%
echo Web Mode: %WEB_MODE%
echo HTTPS Mode: %HTTPS_MODE%
Expand Down Expand Up @@ -153,18 +144,30 @@ k95.exe -Y -# 127 -C "save keymap %manual_dist_dir%default.ksc,exit" > NUL:

REM Copy manual to the output directory updating version numbers, etc, as we go
REM Parameters are: source-directory destination-directory, git-file-dates dry-run dev-mode web-mode use-https
k95.exe %docs_root%\mkdocs.ksc -Y -d -# 127 = %docs_root%\manual %OUT_DIR% %GIT_DATES% %DRY_RUN% %DEV_MODE% %WEB_MODE% %HTTPS_MODE%
k95.exe %docs_root%\mkdocs.ksc -Y -d -# 127 = %docs_root%\manual %OUT_DIR% %GIT_DATES% %DEV_MODE% %WEB_MODE% %HTTPS_MODE% || goto :failed


REM And update modified dates for anything that hasn't changed since the manual
REM was added to git
if "%DRY_RUN%" == "true" goto :skipfd
k95.exe -Y -H -# 127 -C ".manual_dir := %manual_dist_dir%,.modtime_file := %mtime_file%,rexx call setdates,exit"
:skipfd
k95.exe -Y -H -# 127 -C ".manual_dir := %manual_dist_dir%,.modtime_file := %mtime_file%,rexx call setdates,exit" || goto :failed

echo manual done.
goto :finished

:failed
echo K95 Manual build failed with exit status: %errorlevel%
type debug.log
popd

set REGINA_MACROS=%REGINA_MACROS_OLD%
set REGINA_MACROS_OLD=

exit /B 1

:finished
popd

set REGINA_MACROS=%REGINA_MACROS_OLD%
set REGINA_MACROS_OLD=

:end
:end
185 changes: 72 additions & 113 deletions doc/mkdocs.ksc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
; TODO: Add a "prerelease" flag that would add a header to the top of every
; page indicating this documentation is preliminary, etc.

log debug

local ver_maj_min ver_full ver_long_date ver_date ver_date_iso file_last_modified touch_date

; ============================================================================
Expand Down Expand Up @@ -108,16 +110,14 @@ if not defined \%2 usage
.dest := \Fcontents(\%2)

.touch_files := true
.dry_run := false
.dev_mode := false
.web_mode := 1
.use_https := 1

if defined \%3 .touch_files := \%3
if defined \%4 .dry_run := \%4
if defined \%5 .dev_mode := \%5
if defined \%6 .web_mode := \%6
if defined \%7 .use_https := \%7
if defined \%5 .dev_mode := \%4
if defined \%6 .web_mode := \%5
if defined \%7 .use_https := \%6

if \m(dev_mode) {
.dev_mode = 1
Expand Down Expand Up @@ -197,29 +197,6 @@ define date_to_touch_date {
}
}

; ============================================================================
; Function to update tags in a single file

def process_file {
local file_in file_out gitdate git_date
define \%9

.file_in := \Freplace(\%1,/,\\)
.file_out := \Freplace(\%2,/,\\)
.gitdate := \%3

; ============================================================================
; Get file modified date from git if requested
if = \m(gitdate) 1 {
.git_date := \Fcommand(git log -1 --pretty="format:%ci" \m(file_in) 2> nul)
}

; Update the file. This is done in REXX as its easier (regular expressions)
; and faster.
rexx call mkdocs
}


; ============================================================================
; Process files

Expand All @@ -232,71 +209,62 @@ if neq "\Fsubstring(\m(dest),\flength(\m(dest)),1)" "/" {
.dest := \m(dest)/
}

array declare f
array declare f o

dir /array:f /files \m(src)
; HTML files that need transforming
dir /array:f /files \m(src)/*.html

if = \m(web_mode) 0 {
; If not in web-mode, build a list of .html files that will need to be
; renamed to .htm
; Other files that just need copying and maybe touching
dir /array:o /files \m(src)/{*.css,*.gif,*.jpg}

local curdir
array declare g
; Build a list of .html files that need processing

.curdir := \v(directory)
cd \m(src)
dir /array:g /files *.html
cd \m(curdir)
local curdir
array declare g

; mkdocs.rex will pick up the list of .html files to rename from here.
.html_files := \fjoin(&g[],{,})
}
.curdir := \v(directory)
cd \m(src)
dir /array:g /files *.html
cd \m(curdir)

; mkdocs.rex will pick up the list of .html files to rename from here.
.html_files := \fjoin(&g[],{,})

echo HTML Files: \m(html_files)

mkdir \m(dest)

echo Processing \fdim(&f) files...
echo Processing \fdim(&f) HTML files...
echo Hand over to REXX
rexx call mkdocs
echo Back from REXX

.\%x = 1
while <= \%x \fdim(&f) {
.idx := \Fsearch(*.{htm,html},\&f[\%x])
echo Processing \fdim(&o) Other files...

.src_file := \&f[\%x]
.dst_file := \m(dest)\Fbasename(\&f[\%x])
.src_date := \Fdate(\m(src_file))
for \%x 1 \fdim(&o) 1 {
; echo Loop Top iteration \%x of \fdim(&o)

if = \m(idx) 1 {
echo \%x. UPDATE \m(src_file) ---> \m(dst_file)
if \m(dry_run) {
echo process_file \m(src_file) \m(dst_file) \m(touch_files)
} else {
process_file \m(src_file) \m(dst_file) \m(touch_files)
}
}
else {
echo \%x. COPY \m(src_file) ---> \m(dst_file)

if \m(dry_run) {
echo copy /overwrite:always \m(src_file) \m(dst_file)
} else {
copy /overwrite:always \m(src_file) \m(dst_file)
}

if = \m(touch_files) 1 {
; Try with git first, in RFC2822 style: Mon, 19 Aug 2024 19:41:25 +1200
.touch_date := \Fcommand(git log -1 --pretty="format:%cd" --date=format:%Y:%m:%d:%H:%M:%S \m(src_file) 2> nul)

; Convert to the format required by Touch
if = \flength(\m(touch_date)) 0 date_to_touch_date {\m(src_date)} 0
;else date_to_touch_date {\m(gitdate)} 1

if \m(dry_run) {
echo touch /modtime:\m(touch_date) \m(dst_file)
} else {
touch /modtime:\m(touch_date) \m(dst_file)
}
}
}
increment \%x
.file_in := \&o[\%x]
; echo file_in \m(file_in)
.file_out := \m(dest)\Fbasename(\&o[\%x])
; echo file_out \m(file_out)
.src_date := \Fdate(\m(file_in))
; echo src_date \m(src_date)

echo \%x. COPY \m(file_in) ---> \m(file_out)

copy /overwrite:always \m(file_in) \m(file_out)
if fail exit 1

if = \m(touch_files) 1 {
; Try with git first, in RFC2822 style: Mon, 19 Aug 2024 19:41:25 +1200
.touch_date := \Fcommand(git log -1 --pretty="format:%cd" --date=format:%Y:%m:%d:%H:%M:%S \m(file_in) 2> nul)

; Convert to the format required by Touch
if = \flength(\m(touch_date)) 0 date_to_touch_date {\m(src_date)} 0

touch /modtime:\m(touch_date) \m(file_out)
}
}

; TODO: Only do this if the default keymap actually exists
Expand All @@ -310,41 +278,32 @@ echo Updating default keymap HTML file (default.html) from \m(dest)../../keymaps
if = \m(web_mode) 0 {
.defhtm := \m(dest)default.htm
}
if \m(dry_run) {
echo Generate \m(defhtm)
} else {
fopen /read \%i \m(dest)default.ksc
fopen /write \%o \m(defhtm)
fwrite /line \%o {<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN//2.0">}
fwrite /line \%o {<html>}
fwrite /line \%o {<body bgcolor="#ffffff" text="#000000">}
fwrite /line \%o {<pre>}
while true {
undef line
fread /line \%i line
if fail break
fwrite /line \%o \m(line)
}
fwrite /line \%o {</pre>}
fwrite /line \%o {</body></html>}
fclose \%i
fclose \%o
if exist \m(dest)default.ksc del /noask \m(dest)default.ksc

fopen /read \%i \m(dest)default.ksc
fopen /write \%o \m(defhtm)
fwrite /line \%o {<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN//2.0">}
fwrite /line \%o {<html>}
fwrite /line \%o {<body bgcolor="#ffffff" text="#000000">}
fwrite /line \%o {<pre>}
while true {
undef line
fread /line \%i line
if fail break
fwrite /line \%o \m(line)
}
fwrite /line \%o {</pre>}
fwrite /line \%o {</body></html>}
fclose \%i
fclose \%o
if exist \m(dest)default.ksc del /noask \m(dest)default.ksc

if = \m(web_mode) 0 {
echo Swapping around index.htm
if \m(dry_run) {
echo if exist {\m(dest)kermit95.htm} del /noask {\m(dest)kermit95.htm}
echo ren \m(dest)index.htm \m(dest)kermit95.htm
echo ren \m(dest)docindex.htm \m(dest)index.htm
}
else {
if exist {\m(dest)kermit95.htm} del /noask {\m(dest)kermit95.htm}
ren \m(dest)index.htm \m(dest)kermit95.htm
ren \m(dest)docindex.htm \m(dest)index.htm
}

if exist {\m(dest)kermit95.htm} del /noask {\m(dest)kermit95.htm}
ren \m(dest)index.htm \m(dest)kermit95.htm
ren \m(dest)docindex.htm \m(dest)index.htm
}

echo Done
exit
exit
Loading

0 comments on commit 0dbe2c5

Please sign in to comment.