diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index d4508d4b..dbd0d0ca 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -210,7 +210,7 @@ Define domain standardebooks.org # Redirect cover images with caching sha's to the root image # We do this because some sites like Google cache the cover image path, so changing it results in lots of 404s - RewriteRule ^/images/covers/(.+?)\-[a-z0-9]{8}\-(cover|hero)(@2x)?\.jpg$ /images/covers/$1-$2$3.jpg + RewriteRule ^/images/covers/(.+?)\-[a-z0-9]{8}\-(cover|hero)(@2x)?\.(jpg|avif)$ /images/covers/$1-$2$3.$4 RewriteRule ^/ebooks/([^\./]+?)$ /ebooks/author.php?url-path=$1 [QSA] RewriteRule ^/tags/([^\./]+?)$ /ebooks/index.php?tag=$1 [QSA] diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index 32357ee1..5e2167a0 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -209,7 +209,7 @@ Define domain standardebooks.test # Redirect cover images with caching sha's to the root image # We do this because some sites like Google cache the cover image path, so changing it results in lots of 404s - RewriteRule ^/images/covers/(.+?)\-[a-z0-9]{8}\-(cover|hero)(@2x)?\.jpg$ /images/covers/$1-$2$3.jpg + RewriteRule ^/images/covers/(.+?)\-[a-z0-9]{8}\-(cover|hero)(@2x)?\.(jpg|avif)$ /images/covers/$1-$2$3.$4 RewriteRule ^/ebooks/([^\./]+?)$ /ebooks/author.php?url-path=$1 [QSA] RewriteRule ^/tags/([^\./]+?)$ /ebooks/index.php?tag=$1 [QSA] diff --git a/lib/Ebook.php b/lib/Ebook.php index 2e4b5020..542b9c87 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -24,9 +24,13 @@ class Ebook{ public $Identifier; public $UrlSafeIdentifier; public $HeroImageUrl; + public $HeroImageAvifUrl; public $HeroImage2xUrl; + public $HeroImage2xAvifUrl; public $CoverImageUrl; + public $CoverImageAvifUrl; public $CoverImage2xUrl; + public $CoverImage2xAvifUrl; public $DistCoverUrl; public $Title; public $FullTitle; @@ -139,9 +143,13 @@ class Ebook{ } $hash = substr(sha1($this->GitCommits[0]->Timestamp->format('U') . ' ' . $this->GitCommits[0]->Message), 0, 8); $this->CoverImageUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover.jpg'; + $this->CoverImageAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover.avif'; $this->CoverImage2xUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover@2x.jpg'; + $this->CoverImage2xAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover@2x.avif'; $this->HeroImageUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero.jpg'; + $this->HeroImageAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero.avif'; $this->HeroImage2xUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero@2x.jpg'; + $this->HeroImage2xAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero@2x.avif'; // Now do some heavy XML lifting! $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $rawMetadata)); diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www index 8a5baf56..058dd16a 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -69,6 +69,8 @@ require "git" "Try: apt-get install git" require "php" "Try: apt-get install php-cli" require "se" "Read: https://standardebooks.org/tools" +# go-avif is compiled from https://github.com/Kagami/go-avif/ + scriptsDir="$(dirname "$(readlink -f "$0")")" if ! [ -x "${scriptsDir}"/reset-php-fpm-opcache ]; then @@ -136,8 +138,11 @@ do git show HEAD:images/cover.jpg > "${imgWorkDir}/${urlSafeIdentifier}.jpg" cp "${imgWorkDir}/${urlSafeIdentifier}.jpg" "${imgWorkDir}/${urlSafeIdentifier}@2x.jpg" # Resize and crop the image to 2156 width, 720 height, and starting at the coords 0,1078 - convert -resize "1078" -crop "1078x359+0+539" -sampling-factor 4:2:0 -strip -quality 75 -colorspace RGB -interlace JPEG "${imgWorkDir}/${urlSafeIdentifier}.jpg" "${imgWorkDir}/${urlSafeIdentifier}-hero.jpg" - convert -resize "2156" -crop "2156x718+0+1078" -sampling-factor 4:2:0 -strip -quality 75 -colorspace RGB -interlace JPEG "${imgWorkDir}/${urlSafeIdentifier}@2x.jpg" "${imgWorkDir}/${urlSafeIdentifier}-hero@2x.jpg" + convert -resize "1078" -crop "1078x359+0+539" -sampling-factor 4:2:0 -strip -quality 100 -colorspace RGB -interlace JPEG "${imgWorkDir}/${urlSafeIdentifier}.jpg" "${imgWorkDir}/${urlSafeIdentifier}-hero.jpg" + convert -resize "2156" -crop "2156x718+0+1078" -sampling-factor 4:2:0 -strip -quality 100 -colorspace RGB -interlace JPEG "${imgWorkDir}/${urlSafeIdentifier}@2x.jpg" "${imgWorkDir}/${urlSafeIdentifier}-hero@2x.jpg" + + "${scriptsDir}"/go-avif -e "${imgWorkDir}/${urlSafeIdentifier}-hero.jpg" -o "${imgWorkDir}/${urlSafeIdentifier}-hero.avif" --best + "${scriptsDir}"/go-avif -e "${imgWorkDir}/${urlSafeIdentifier}-hero@2x.jpg" -o "${imgWorkDir}/${urlSafeIdentifier}-hero@2x.avif" --best # Build the cover image thumbnail # We use JPG instead of SVG for several reasons: @@ -158,9 +163,15 @@ do convert -resize "196" -sampling-factor 4:2:0 -strip -quality 75 -colorspace RGB -interlace JPEG "${imgWorkDir}/${urlSafeIdentifier}.png" "${imgWorkDir}/${urlSafeIdentifier}.jpg" convert -resize "392" -sampling-factor 4:2:0 -strip -quality 75 -colorspace RGB -interlace JPEG "${imgWorkDir}/${urlSafeIdentifier}@2x.png" "${imgWorkDir}/${urlSafeIdentifier}@2x.jpg" + "${scriptsDir}"/go-avif -e "${imgWorkDir}/${urlSafeIdentifier}.jpg" -o "${imgWorkDir}/${urlSafeIdentifier}.avif" --best + "${scriptsDir}"/go-avif -e "${imgWorkDir}/${urlSafeIdentifier}@2x.jpg" -o "${imgWorkDir}/${urlSafeIdentifier}@2x.avif" --best + mv "${imgWorkDir}/${urlSafeIdentifier}@2x.jpg" "${imgWorkDir}/${urlSafeIdentifier}-cover@2x.jpg" mv "${imgWorkDir}/${urlSafeIdentifier}.jpg" "${imgWorkDir}/${urlSafeIdentifier}-cover.jpg" + mv "${imgWorkDir}/${urlSafeIdentifier}@2x.avif" "${imgWorkDir}/${urlSafeIdentifier}-cover@2x.avif" + mv "${imgWorkDir}/${urlSafeIdentifier}.avif" "${imgWorkDir}/${urlSafeIdentifier}-cover.avif" + sudo chgrp --preserve-root --recursive "${group}" "${imgWorkDir}/${urlSafeIdentifier}"* sudo chmod --preserve-root --recursive g+w "${imgWorkDir}/${urlSafeIdentifier}"* @@ -198,7 +209,7 @@ do mv "${workDir}"/* "${webDir}/" # Move the cover images over - mv "${imgWorkDir}/${urlSafeIdentifier}"*.jpg "${webRoot}/www/images/covers/" + mv "${imgWorkDir}/${urlSafeIdentifier}"*.{jpg,avif} "${webRoot}/www/images/covers/" # Delete the now-empty work dir (empty except for .git) rm --preserve-root --recursive --force "${workDir}" "${imgWorkDir}" diff --git a/scripts/go-avif b/scripts/go-avif new file mode 100755 index 00000000..a1e15264 Binary files /dev/null and b/scripts/go-avif differ diff --git a/templates/EbookGrid.php b/templates/EbookGrid.php index 46307ff9..cfbede62 100644 --- a/templates/EbookGrid.php +++ b/templates/EbookGrid.php @@ -6,7 +6,13 @@ if(!isset($ebooks)){
  1. - The cover for the Standard Ebooks edition of <?= Formatter::ToPlainText($ebook->Title) ?> + + + + + The cover for the Standard Ebooks edition of <?= Formatter::ToPlainText(strip_tags($ebook->TitleWithCreditsHtml)) ?> + +

    Title) ?>

    Authors as $author){ ?>

    Name) ?>

    diff --git a/www/css/core.css b/www/css/core.css index 50c2773b..aea223fb 100644 --- a/www/css/core.css +++ b/www/css/core.css @@ -687,8 +687,7 @@ article.ebook > header > div a:visited{ text-decoration: none; } -article.ebook > header > img{ - width: 100%; +article.ebook > header img{ top: 0; left: 0; position: absolute; diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 463440ff..02d8647a 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -44,10 +44,18 @@ try{ $ebooks = Library::GetEbooks(); shuffle($ebooks); - for($i = 0; $i < 5; $i++){ - if(isset($ebooks[$i])){ + $targetCarouselSize = 5; + if(sizeof($ebooks) < $targetCarouselSize){ + $targetCarouselSize = sizeof($ebooks); + } + + $i = 0; + while(sizeof($carousel) < $targetCarouselSize){ + if(isset($ebooks[$i]) && $ebooks[$i]->Url !== $ebook->Url){ $carousel[] = $ebooks[$i]; } + + $i++; } } catch(SeeOtherEbookException $ex){ @@ -70,7 +78,11 @@ catch(\Exception $ex){

    Name) ?>

    - The cover for the Standard Ebooks edition of <?= $ebook->Title ?>. + + + + The cover for the Standard Ebooks edition of <?= Formatter::ToPlainText(strip_tags($ebook->TitleWithCreditsHtml)) ?> +