Add --weburl parameter.

This commit is contained in:
Danny Bautista 2019-06-07 14:14:21 -04:00 committed by Alex Cabal
parent 8349f9268b
commit 46fe654fac
4 changed files with 28 additions and 15 deletions

View file

@ -9,3 +9,5 @@ To use, call this script with the directories of the books you want to deploy as
The default web root is /standardebooks.org. If it is located elsewhere, specify it with the --webroot option. For instance, `deploy-ebook-to-www --webroot /var/www/html /path/to/ebook`. Note that there will be php errors if the git repositories are not in the ebook directory immediately in the web root. Either keep them there or create a symlink. The default web root is /standardebooks.org. If it is located elsewhere, specify it with the --webroot option. For instance, `deploy-ebook-to-www --webroot /var/www/html /path/to/ebook`. Note that there will be php errors if the git repositories are not in the ebook directory immediately in the web root. Either keep them there or create a symlink.
The default group is se. to use a different one, specify it with the --group option. For instance, to use this script inside the included Vagrant VM, which uses the www-data group, use `deploy-ebook-to-www --group www-data /path/to/ebook`. The default group is se. to use a different one, specify it with the --group option. For instance, to use this script inside the included Vagrant VM, which uses the www-data group, use `deploy-ebook-to-www --group www-data /path/to/ebook`.
The default URL is `https://standardebooks.org`. To change it, use the --weburl option. For example, `deploy-ebook-to-www --weburl "http://localhost:8080". This option will cause deploy-ebook-to-www to use the specified URL in the generated opds and rss files. Care should be taken however; the URL `https://standardebooks.org` is hardcoded in a few places, even when `SITE_URL` is changed to a custom URL, so for testing, it may be more convenient to simply use /etc/hosts or a similar mechanism to resolve `standardebooks.org` to `127.0.0.1`.

View file

@ -6,10 +6,11 @@ DESCRIPTION
Deploy a Standard Ebook source repository to the web. Deploy a Standard Ebook source repository to the web.
USAGE USAGE
deploy-ebook-to-www [-v,--verbose] [-g,--group GROUP] [--webroot WEBROOT] DIRECTORY [DIRECTORY...] deploy-ebook-to-www [-v,--verbose] [-g,--group GROUP] [--webroot WEBROOT] [--weburl WEBURL] DIRECTORY [DIRECTORY...]
DIRECTORY is a bare source repository. DIRECTORY is a bare source repository.
GROUP is a groupname. Defaults to "se". GROUP is a groupname. Defaults to "se".
WEBROOT is the path to your webroot. Defaults to "/standardebooks.org". WEBROOT is the path to your webroot. Defaults to "/standardebooks.org".
WEBURL is the URL the website is served on. Defaults to "https://standardebooks.org".
EOF EOF
exit exit
} }
@ -20,6 +21,7 @@ require(){ command -v "$1" > /dev/null 2>&1 || { suggestion=""; if [ -n "$2" ];
verbose="false" verbose="false"
group="se" group="se"
webRoot="/standardebooks.org" webRoot="/standardebooks.org"
webUrl="https://standardebooks.org"
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
usage usage
@ -43,6 +45,11 @@ while [ $# -gt 0 ]; do
webRoot="$2" webRoot="$2"
shift 2 shift 2
;; ;;
--weburl)
[ -n "$2" ] || die "Web URL can't be empty."
webUrl="$2"
shift 2
;;
*) break ;; *) break ;;
esac esac
done done
@ -210,7 +217,7 @@ if [ "${verbose}" = "true" ]; then
printf "Rebuilding OPDS catalog ... " printf "Rebuilding OPDS catalog ... "
fi fi
bash -c "php \"${scriptsDir}\"/generate-opds.php --webroot \"${webRoot}\" > \"${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; 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 -"
if [ "${verbose}" = "true" ]; then if [ "${verbose}" = "true" ]; then
printf "Done.\n" printf "Done.\n"
@ -221,7 +228,7 @@ if [ "${verbose}" = "true" ]; then
printf "Rebuilding new releases RSS feed ... " printf "Rebuilding new releases RSS feed ... "
fi fi
bash -c "php \"${scriptsDir}\"/generate-rss.php --webroot \"${webRoot}\" > \"${webRoot}\"/www/rss/new-releases.xml" bash -c "php \"${scriptsDir}\"/generate-rss.php --webroot \"${webRoot}\" --weburl \"${webUrl}\" > \"${webRoot}\"/www/rss/new-releases.xml"
if [ "${verbose}" = "true" ]; then if [ "${verbose}" = "true" ]; then
printf "Done.\n" printf "Done.\n"

View file

@ -1,23 +1,24 @@
<? <?
$longopts = array("webroot:"); $longopts = array("webroot:", "weburl:");
$options = getopt("", $longopts); $options = getopt("", $longopts);
$webRoot = $options["webroot"] ?? "/standardebooks.org"; $webRoot = $options["webroot"] ?? "/standardebooks.org";
$webUrl = $options["weburl"] ?? "https://standardebooks.org";
$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') ?? ''));
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/">
<id>https://standardebooks.org/opds/all</id> <id><?= $webUrl ?>/opds/all</id>
<link href="https://standardebooks.org/opds/all" rel="self" type="application/atom+xml;profile=opds-catalog;kind=acquisition"/> <link href="<?= $webUrl ?>/opds/all" rel="self" type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
<link href="https://standardebooks.org/opds/" rel="start" type="application/atom+xml;profile=opds-catalog;kind=navigation"/> <link href="<?= $webUrl ?>/opds/" rel="start" type="application/atom+xml;profile=opds-catalog;kind=navigation"/>
<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>https://standardebooks.org/images/logo.png</icon> <icon><?= $webUrl ?>/images/logo.png</icon>
<updated><?= gmdate('Y-m-d\TH:i:s\Z') ?></updated> <updated><?= gmdate('Y-m-d\TH:i:s\Z') ?></updated>
<author> <author>
<name>Standard Ebooks</name> <name>Standard Ebooks</name>
<uri>https://standardebooks.org</uri> <uri><?= $webUrl ?></uri>
</author> </author>
<? foreach($contentFiles as $path){ <? foreach($contentFiles as $path){
if($path == '') if($path == '')
@ -29,7 +30,8 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
$authors = array(); $authors = array();
$temp = $xml->xpath('/package/metadata/dc:identifier') ?: []; $temp = $xml->xpath('/package/metadata/dc:identifier') ?: [];
$url = preg_replace('/^url:/ius', '', (string)array_shift($temp)) ?? ''; $url = preg_replace('/^url:/ius', '', (string)array_shift($temp)) ?? '';
$relativeUrl = preg_replace('/^https:\/\/standardebooks.org/ius', '', $url) ?? ''; $url = preg_replace('/^https:\/\/standardebooks.org/ius', $webUrl, $url) ?? '';
$relativeUrl = preg_replace('/^' . preg_quote($webUrl, '/') . '/ius', '', $url) ?? '';
$temp = $xml->xpath('/package/metadata/dc:title') ?: []; $temp = $xml->xpath('/package/metadata/dc:title') ?: [];
$title = array_shift($temp); $title = array_shift($temp);

View file

@ -1,7 +1,8 @@
<? <?
$longopts = array("webroot:"); $longopts = array("webroot:", "weburl:");
$options = getopt("", $longopts); $options = getopt("", $longopts);
$webRoot = $options["webroot"] ?? "/standardebooks.org"; $webRoot = $options["webroot"] ?? "/standardebooks.org";
$webUrl = $options["weburl"] ?? "https://standardebooks.org";
$rssLength = 30; $rssLength = 30;
$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') ?? ''));
@ -30,24 +31,25 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\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>
<title>Standard Ebooks - New Releases</title> <title>Standard Ebooks - New Releases</title>
<link>https://standardebooks.org</link> <link><?= $webUrl ?></link>
<description>A list of the <?= number_format($rssLength) ?> latest Standard Ebooks ebook releases, most-recently-released first.</description> <description>A list of the <?= number_format($rssLength) ?> latest Standard Ebooks ebook releases, most-recently-released first.</description>
<language>en-US</language> <language>en-US</language>
<copyright>https://creativecommons.org/publicdomain/zero/1.0/</copyright> <copyright>https://creativecommons.org/publicdomain/zero/1.0/</copyright>
<lastBuildDate><?= gmdate('D, d M Y H:i:s +0000') ?></lastBuildDate> <lastBuildDate><?= gmdate('D, d M Y H:i:s +0000') ?></lastBuildDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs> <docs>http://blogs.law.harvard.edu/tech/rss</docs>
<atom:link href="https://standardebooks.org/rss/new-releases" rel="self" type="application/rss+xml" /> <atom:link href="<?= $webUrl ?>/rss/new-releases" rel="self" type="application/rss+xml" />
<image> <image>
<url>https://standardebooks.org/images/logo-rss.png</url> <url><?= $webUrl ?>/images/logo-rss.png</url>
<title>Standard Ebooks - New Releases</title> <title>Standard Ebooks - New Releases</title>
<description>The Standard Ebooks logo</description> <description>The Standard Ebooks logo</description>
<link>https://standardebooks.org</link> <link><?= $webUrl ?></link>
<height>144</height> <height>144</height>
<width>144</width> <width>144</width>
</image> </image>
<? foreach($sortedContentFiles as $xml){ <? foreach($sortedContentFiles as $xml){
$temp = $xml->xpath('/package/metadata/dc:identifier') ?: []; $temp = $xml->xpath('/package/metadata/dc:identifier') ?: [];
$url = preg_replace('/^url:/ius', '', (string)array_shift($temp) ?? '') ?? ''; $url = preg_replace('/^url:/ius', '', (string)array_shift($temp) ?? '') ?? '';
$url = preg_replace('/^https:\/\/standardebooks.org/ius', $webUrl, $url) ?? '';
$temp = $xml->xpath('/package/metadata/dc:title') ?: []; $temp = $xml->xpath('/package/metadata/dc:title') ?: [];
$title = array_shift($temp) ?? ''; $title = array_shift($temp) ?? '';