diff --git a/scripts/generate-opds.php b/scripts/generate-opds.php
index c27924cc..818c0459 100755
--- a/scripts/generate-opds.php
+++ b/scripts/generate-opds.php
@@ -7,28 +7,50 @@ $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') ?? ''));
+$sortedContentFiles = [];
+
+foreach($contentFiles as $path){
+ if($path == '')
+ continue;
+
+ $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents($path) ?: ''));
+ $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
+
+ $updated = $xml->xpath('/package/metadata/meta[@property="dcterms:modified"]') ?: [];
+
+ if($updated !== false && sizeof($updated) > 0){
+ $sortedContentFiles[(string)$updated[0]] = $xml;
+ }
+}
+
+krsort($sortedContentFiles);
ob_start();
print("\n");
+
+/* Notes:
+
+- *All* OPDS feeds must contain a rel="crawlable" link pointing to the /opds/all feed
+
+- The element is required to note this as a "Complete Acquisition Feeds"; see https://specs.opds.io/opds-1.2#25-complete-acquisition-feeds
+
+*/
?>
-
+
= $webUrl ?>/opds/all
+
All Standard Ebooks
Free and liberated ebooks, carefully produced for the true book lover.
= $webUrl ?>/images/logo.png
= $updatedTimestamp ?>
+
Standard Ebooks
= $webUrl ?>
- foreach($contentFiles as $path){
- if($path == '')
- continue;
-
- $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents("$path") ?: ''));
- $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
+ foreach($sortedContentFiles as $xml){
$authors = array();
$temp = $xml->xpath('/package/metadata/dc:identifier') ?: [];
@@ -90,6 +112,7 @@ print("\n");
} ?>
= $published ?>
+ = $published ?>
= $modified ?>
= $language ?>
Standard Ebooks