From 46fe654fac4959b8a8844ef91ea2b9ef58ccb902 Mon Sep 17 00:00:00 2001 From: Danny Bautista Date: Fri, 7 Jun 2019 14:14:21 -0400 Subject: [PATCH] Add --weburl parameter. --- scripts/README.md | 2 ++ scripts/deploy-ebook-to-www | 13 ++++++++++--- scripts/generate-opds.php | 16 +++++++++------- scripts/generate-rss.php | 12 +++++++----- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index bf0e68c4..aa4988be 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -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 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`. diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www index 96208c31..f6a4c759 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -6,10 +6,11 @@ DESCRIPTION Deploy a Standard Ebook source repository to the web. 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. GROUP is a groupname. Defaults to "se". 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 exit } @@ -20,6 +21,7 @@ require(){ command -v "$1" > /dev/null 2>&1 || { suggestion=""; if [ -n "$2" ]; verbose="false" group="se" webRoot="/standardebooks.org" +webUrl="https://standardebooks.org" if [ $# -eq 0 ]; then usage @@ -43,6 +45,11 @@ while [ $# -gt 0 ]; do webRoot="$2" shift 2 ;; + --weburl) + [ -n "$2" ] || die "Web URL can't be empty." + webUrl="$2" + shift 2 + ;; *) break ;; esac done @@ -210,7 +217,7 @@ if [ "${verbose}" = "true" ]; then printf "Rebuilding OPDS catalog ... " 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\" \"\" && 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\" \"\" && cat) | xmllint --output \"${webRoot}\"/www/opds/all.xml --format -" if [ "${verbose}" = "true" ]; then printf "Done.\n" @@ -221,7 +228,7 @@ if [ "${verbose}" = "true" ]; then printf "Rebuilding new releases RSS feed ... " 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 printf "Done.\n" diff --git a/scripts/generate-opds.php b/scripts/generate-opds.php index 4f77c169..7c8ccc6c 100755 --- a/scripts/generate-opds.php +++ b/scripts/generate-opds.php @@ -1,23 +1,24 @@ \n"); ?> - https://standardebooks.org/opds/all - - + /opds/all + + All Standard Ebooks Free and liberated ebooks, carefully produced for the true book lover. - https://standardebooks.org/images/logo.png + /images/logo.png Standard Ebooks - https://standardebooks.org + \n"); $authors = array(); $temp = $xml->xpath('/package/metadata/dc:identifier') ?: []; $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') ?: []; $title = array_shift($temp); diff --git a/scripts/generate-rss.php b/scripts/generate-rss.php index ae544b1d..387f3347 100644 --- a/scripts/generate-rss.php +++ b/scripts/generate-rss.php @@ -1,7 +1,8 @@ \n"); Standard Ebooks - New Releases - https://standardebooks.org + A list of the latest Standard Ebooks ebook releases, most-recently-released first. en-US https://creativecommons.org/publicdomain/zero/1.0/ http://blogs.law.harvard.edu/tech/rss - + - https://standardebooks.org/images/logo-rss.png + /images/logo-rss.png Standard Ebooks - New Releases The Standard Ebooks logo - https://standardebooks.org + 144 144 xpath('/package/metadata/dc:identifier') ?: []; $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') ?: []; $title = array_shift($temp) ?? '';