sasanarakkha / pali-english-recitations

Sāsanārakkha Pāli-English Recitations
https://sasanarakkha.org/
Other
8 stars 1 forks source link

Automatically Update Date/Timestamp in HTML Before Building EPUB #16

Closed paladhammika closed 1 year ago

paladhammika commented 1 year ago

@bergentroll

# Update the date
cd manuscript/html/OEBPS/Text
TODAY=$(date --iso-8601)
sed -i 's/\(This version was created on:\) *[0-9-]\{10\}/\1 '"$TODAY"'/' copyright.xhtml
cd ../../..

The above is some sed magic which was used in earlier versions of this project. It automatically changed the time stamp (seen in the picture below) with each build.

image

Attempts to implement this into the current Makefile have not been successful. Would you have any suggestions?

image

bergentroll commented 1 year ago

If you try to put @echo [${PWD}] after cd ..., bhante, you may note that cd takes not effect. It seems like shell specific in Make. You are able to use the following construction:

        @sed -i 's/\(This version was created on:\) *[0-9-]\{10\}/\1 '"$TODAY"'/' manuscript/html/OEBPS/Text/copyright.xhtml

Or even this one:

        @cd manuscript/html/OEBPS/Text && sed -i 's/\(This version was created on:\) *[0-9-]\{10\}/\1 '"$TODAY"'/' copyright.xhtml

There is also no need to do cd ../../../ because it will not take effect too.

Also there will be a problem with the $TODAY variable. You may set and use it e.g. in a such way:

TODAY=$(shell date --iso-8601)
...

epub: $(EPUBFILE)
$(EPUBFILE): $(SOURCEFILES)
        ...
        @sed -i 's/\(This version was created on:\) *[0-9-]\{10\}/\1 '"$(TODAY)"'/' manuscript/html/OEBPS/Text/copyright.xhtml
        ...

(... is for some other relative code).

❤️🙏🙏🙏

paladhammika commented 1 year ago

Sādhu! This was helpful.

I had to use sed within an enclosed shell command otherwise it would fail to produce the EPUB.

@$(shell command sed -i 's/\(This version was created on:\) *[0-9-]\{10\}/\1 '"$(TODAY)"'/' manuscript/html/OEBPS/Text/copyright.xhtml)