Continue improving serving and display of RSS/OPDS

This commit is contained in:
Alex Cabal 2022-06-20 11:31:58 -05:00
parent 06787c5f57
commit 37830e173f
5 changed files with 29 additions and 13 deletions

View file

@ -96,16 +96,23 @@ Define webroot /standardebooks.org/web
Header set Content-Disposition "attachment; filename=%{FILENAME}e" Header set Content-Disposition "attachment; filename=%{FILENAME}e"
</Location> </Location>
<Location ~ ^/opds.+?$>
DirectoryIndex index.xml
</location>
# We explicitly set the content-type for items in the /vocab/ directory, because Apache doesn't set it for us, # We explicitly set the content-type for items in the /vocab/ directory, because Apache doesn't set it for us,
# and we need a content-type header when using the "nosniff" header. See https://bugzilla.mozilla.org/show_bug.cgi?id=1547076 # and we need a content-type header when using the "nosniff" header. See https://bugzilla.mozilla.org/show_bug.cgi?id=1547076
<Location ~ ^/vocab/.+$> <Location ~ ^/vocab/.+$>
Header set Content-Type "text/plain" Header set Content-Type "text/plain"
</location> </location>
# text/xml allows the page to be displayed in a browser. application/atom+xml will cause it to be downloaded.
<Location ~ ^/opds.+?$>
DirectoryIndex index.xml
Header set Content-Type "text/xml"
</location>
# text/xml allows the page to be displayed in a browser. application/rss+xml will cause it to be downloaded.
<Location ~ ^/rss/.*$>
Header set Content-Type "text/xml"
</Location>
# Enable HTTP CORS so that browser-based readers like Readium can access opds and ebooks # Enable HTTP CORS so that browser-based readers like Readium can access opds and ebooks
# Allow fonts for newsletter emails # Allow fonts for newsletter emails
# See https://github.com/standardebooks/tools/issues/2 # See https://github.com/standardebooks/tools/issues/2

View file

@ -95,16 +95,23 @@ Define webroot /standardebooks.org/web
Header set Content-Disposition "attachment; filename=%{FILENAME}e" Header set Content-Disposition "attachment; filename=%{FILENAME}e"
</Location> </Location>
<Location ~ ^/opds.+?$>
DirectoryIndex index.xml
</location>
# We explicitly set the content-type for items in the /vocab/ directory, because Apache doesn't set it for us, # We explicitly set the content-type for items in the /vocab/ directory, because Apache doesn't set it for us,
# and we need a content-type header when using the "nosniff" header. See https://bugzilla.mozilla.org/show_bug.cgi?id=1547076 # and we need a content-type header when using the "nosniff" header. See https://bugzilla.mozilla.org/show_bug.cgi?id=1547076
<Location ~ ^/vocab/.+$> <Location ~ ^/vocab/.+$>
Header set Content-Type "text/plain" Header set Content-Type "text/plain"
</location> </location>
# text/xml allows the page to be displayed in a browser. application/atom+xml will cause it to be downloaded.
<Location ~ ^/opds.+?$>
DirectoryIndex index.xml
Header set Content-Type "text/xml"
</location>
# text/xml allows the page to be displayed in a browser. application/rss+xml will cause it to be downloaded.
<Location ~ ^/rss/.*$>
Header set Content-Type "text/xml"
</Location>
# Enable HTTP CORS so that browser-based readers like Readium can access opds and ebooks # Enable HTTP CORS so that browser-based readers like Readium can access opds and ebooks
# Allow fonts for newsletter emails # Allow fonts for newsletter emails
# See https://github.com/standardebooks/tools/issues/2 # See https://github.com/standardebooks/tools/issues/2

View file

@ -35,7 +35,8 @@ krsort($sortedContentFiles);
$sortedContentFiles = array_slice($sortedContentFiles, 0, $rssLength); $sortedContentFiles = array_slice($sortedContentFiles, 0, $rssLength);
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"/rss/style\" type=\"application/xslt+xml\"?>\n"); // XSL stylesheet mime type must be `text/xsl` otherwise Chrome doesn't read it
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"/rss/style\" type=\"text/xsl\"?>\n");
?> ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>

View file

@ -17,7 +17,6 @@ catch(\Exception $ex){
include(WEB_ROOT . '/404.php'); include(WEB_ROOT . '/404.php');
exit(); exit();
} }
header('Content-type: text/xml');
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/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:schema="http://schema.org/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">

View file

@ -1,10 +1,12 @@
<? <?
require_once('Core.php'); require_once('Core.php');
header('content-type: application/xslt+xml');
// `text/xsl` is the only mime type recognized by Chrome for XSL stylesheets
header('Content-Type: text/xsl');
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n") print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
?> ?>
<xsl:stylesheet version="3.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom"> <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output method="html" html-version="5.0" encoding="utf-8" indent="true"/> <xsl:output method="html" html-version="5.0" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/> <? /* doctype-system outputs the HTML5 doctype */ ?>
<xsl:template match="/"> <xsl:template match="/">
<?= Template::Header(['xmlDeclaration' => false]) ?> <?= Template::Header(['xmlDeclaration' => false]) ?>
<main> <main>