diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www
index 9a801fe7..1178af4b 100755
--- a/scripts/deploy-ebook-to-www
+++ b/scripts/deploy-ebook-to-www
@@ -227,7 +227,7 @@ if [ "${verbose}" = "true" ]; then
printf "Rebuilding OPDS catalog ... "
fi
-bash -c "php \"${scriptsDir}\"/generate-opds.php --webroot \"${webRoot}\" --weburl \"${webUrl}\" > \"${webRoot}\"/www/opds/all.xml; export XMLLINT_INDENT=\$(printf \"\\t\") && xmllint --c14n \"${webRoot}\"/www/opds/all.xml | (printf \"%s\\n\" \"\" && cat) | xmllint --output \"${webRoot}\"/www/opds/all.xml --format -"
+bash -c "php \"${scriptsDir}\"/generate-opds.php --webroot \"${webRoot}\" --weburl \"${webUrl}\" > \"${webRoot}\"/www/opds/all.xml"
if [ "${verbose}" = "true" ]; then
printf "Done.\n"
diff --git a/scripts/generate-opds.php b/scripts/generate-opds.php
index 5e0997d4..c1881b80 100755
--- a/scripts/generate-opds.php
+++ b/scripts/generate-opds.php
@@ -4,8 +4,11 @@ $options = getopt("", $longopts);
$webRoot = $options["webroot"] ?? "/standardebooks.org/web";
$webUrl = $options["weburl"] ?? "https://standardebooks.org";
+$updatedTimestamp = gmdate('Y-m-d\TH:i:s\Z');
+
$contentFiles = explode("\n", trim(shell_exec('find ' . escapeshellarg($webRoot . '/www/ebooks/') . ' -name "content.opf" | sort') ?? ''));
+ob_start();
print("\n");
?>
@@ -15,7 +18,7 @@ print("\n");
All Standard Ebooks
Free and liberated ebooks, carefully produced for the true book lover.
= $webUrl ?>/images/logo.png
- = gmdate('Y-m-d\TH:i:s\Z') ?>
+ = $updatedTimestamp ?>
Standard Ebooks
= $webUrl ?>
@@ -108,3 +111,38 @@ print("\n");
} ?>
+
+
+// Print the "all feed" to file
+$feed = ob_get_contents();
+ob_end_clean();
+
+file_put_contents('/tmp/all.xml', $feed);
+exec('se clean /tmp/all.xml');
+
+// If the feed has changed compared to the version currently on disk, copy our new version over
+// and update the updated timestamp in the master opds index.
+try{
+ if(filesize($webRoot . '/www/opds/all.xml') !== filesize('/tmp/all.xml')){
+ $oldFeed = file_get_contents($webRoot . '/www/opds/all.xml');
+ $newFeed = file_get_contents('/tmp/all.xml');
+ if($oldFeed != $newFeed){
+ file_put_contents($webRoot . '/www/opds/all.xml', $newFeed);
+
+ // Update the index feed with the last updated timestamp
+ $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents($webRoot . '/www/opds/index.xml')));
+ $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
+ $xml->registerXPathNamespace('schema', 'http://schema.org/');
+
+ $allUpdated = $xml->xpath('/feed/entry[id="https://standardebooks.org/opds/all"]/updated')[0];
+ $allUpdated[0] = $updatedTimestamp;
+ file_put_contents($webRoot . '/www/opds/index.xml', str_replace(" ns=", " xmlns=", $xml->asXml()));
+ exec('se clean ' . escapeshellarg($webRoot) . '/www/opds/index.xml');
+ }
+ }
+}
+catch(Exception $ex){
+ rename('/tmp/all.xml', $webRoot . '/www/opds/all.xml');
+}
+
+?>
diff --git a/www/opds/index.xml b/www/opds/index.xml
index 00f9d33c..562fbf81 100644
--- a/www/opds/index.xml
+++ b/www/opds/index.xml
@@ -14,7 +14,7 @@
All Standard Ebooks
- 2015-05-22T04:02:12Z
+ 2020-06-01T03:17:56Z
https://standardebooks.org/opds/all
A list of all Standard Ebooks.