mirror of
https://github.com/standardebooks/web.git
synced 2025-07-07 15:20:32 -04:00
When updating the 'all' OPDS feed, update the master index updated timestamp as well
This commit is contained in:
parent
fcfc1ce55e
commit
374465de55
3 changed files with 41 additions and 3 deletions
|
@ -227,7 +227,7 @@ if [ "${verbose}" = "true" ]; then
|
||||||
printf "Rebuilding OPDS catalog ... "
|
printf "Rebuilding OPDS catalog ... "
|
||||||
fi
|
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\" \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\" && 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
|
if [ "${verbose}" = "true" ]; then
|
||||||
printf "Done.\n"
|
printf "Done.\n"
|
||||||
|
|
|
@ -4,8 +4,11 @@ $options = getopt("", $longopts);
|
||||||
$webRoot = $options["webroot"] ?? "/standardebooks.org/web";
|
$webRoot = $options["webroot"] ?? "/standardebooks.org/web";
|
||||||
$webUrl = $options["weburl"] ?? "https://standardebooks.org";
|
$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') ?? ''));
|
$contentFiles = explode("\n", trim(shell_exec('find ' . escapeshellarg($webRoot . '/www/ebooks/') . ' -name "content.opf" | sort') ?? ''));
|
||||||
|
|
||||||
|
ob_start();
|
||||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||||
?>
|
?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:schema="http://schema.org/">
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:schema="http://schema.org/">
|
||||||
|
@ -15,7 +18,7 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||||
<title>All Standard Ebooks</title>
|
<title>All Standard Ebooks</title>
|
||||||
<subtitle>Free and liberated ebooks, carefully produced for the true book lover.</subtitle>
|
<subtitle>Free and liberated ebooks, carefully produced for the true book lover.</subtitle>
|
||||||
<icon><?= $webUrl ?>/images/logo.png</icon>
|
<icon><?= $webUrl ?>/images/logo.png</icon>
|
||||||
<updated><?= gmdate('Y-m-d\TH:i:s\Z') ?></updated>
|
<updated><?= $updatedTimestamp ?></updated>
|
||||||
<author>
|
<author>
|
||||||
<name>Standard Ebooks</name>
|
<name>Standard Ebooks</name>
|
||||||
<uri><?= $webUrl ?></uri>
|
<uri><?= $webUrl ?></uri>
|
||||||
|
@ -108,3 +111,38 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||||
</entry>
|
</entry>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
</feed>
|
</feed>
|
||||||
|
<?
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<entry>
|
<entry>
|
||||||
<title>All Standard Ebooks</title>
|
<title>All Standard Ebooks</title>
|
||||||
<link href="/opds/all" type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
<link href="/opds/all" type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
||||||
<updated>2015-05-22T04:02:12Z</updated>
|
<updated>2020-06-01T03:17:56Z</updated>
|
||||||
<id>https://standardebooks.org/opds/all</id>
|
<id>https://standardebooks.org/opds/all</id>
|
||||||
<content type="text">A list of all Standard Ebooks.</content>
|
<content type="text">A list of all Standard Ebooks.</content>
|
||||||
</entry>
|
</entry>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue