Fixing summary export

master
Julien Rosset 5 months ago
parent 9c45b474dd
commit 9c2a57f4bb

@ -25,7 +25,7 @@ use Twig\Loader\ArrayLoader;
use ZipArchive; use ZipArchive;
/** /**
* The "main" command * The “main” command
*/ */
class Main { class Main {
/** /**
@ -34,14 +34,16 @@ class Main {
private const string ARGUMENT_FILES = 'files'; private const string ARGUMENT_FILES = 'files';
private const string DOM_NAMESPACE_ATTRIBUTE = 'http://www.w3.org/2000/xmlns/'; private const string DOM_NAMESPACE_ATTRIBUTE = 'http://www.w3.org/2000/xmlns/';
private const string OPF_NAMESPACE_DC = 'http://purl.org/dc/elements/1.1/'; /** @noinspection HttpUrlsUsage */
private const string OPF_NAMESPACE_OPF = 'http://www.idpf.org/2007/opf'; private const string OPF_NAMESPACE_DC = 'http://purl.org/dc/elements/1.1/';
/** @noinspection HttpUrlsUsage */
private const string OPF_NAMESPACE_OPF = 'http://www.idpf.org/2007/opf';
private const string TWIG_TEMPLATE_METADATA_DESCRIPTION = 'metadata_description.html'; private const string TWIG_TEMPLATE_METADATA_DESCRIPTION = 'metadata_description.html';
private const array TWIG_TEMPLATES = [ private const array TWIG_TEMPLATES = [
self::TWIG_TEMPLATE_METADATA_DESCRIPTION => <<<'TWIG' self::TWIG_TEMPLATE_METADATA_DESCRIPTION => <<<'TWIG'
<div> <div>
<p>{{ description }}</p> <p>{{ summary }}</p>
<p><strong>Chapters:</strong> {{ chapters ?? 1 }}</p> <p><strong>Chapters:</strong> {{ chapters ?? 1 }}</p>
<p><strong>Word count:</strong> {{ words }}</p> <p><strong>Word count:</strong> {{ words }}</p>
<p><strong>Published:</strong> {{ publishDate }}</p> <p><strong>Published:</strong> {{ publishDate }}</p>
@ -478,12 +480,12 @@ EOF
} }
//endregion //endregion
//region Delete description if present //region Delete description if present
//region Deletion form DOM //region Deletion from DOM
$rootFileDirty = false; $rootFileDirty = false;
/** @noinspection HttpUrlsUsage */ /** @noinspection HttpUrlsUsage */
$rootFileXPath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); $rootFileXPath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
if (($descriptionNodeList = $rootFileXPath->query('/r:package/r:metadata/dc:description')) !== false && $descriptionNodeList->count() > 0) { if (($descriptionNodeList = $rootFileXPath->query('/r:package/r:metadata/dc:description')) !== false && $descriptionNodeList->count() > 0) {
$output->writeln($descriptionNodeList->count() . ' descriptions found → removing', OutputInterface::VERBOSITY_VERBOSE); $output->writeln($descriptionNodeList->count() . ' existing descriptions found → removing', OutputInterface::VERBOSITY_VERBOSE);
/** @var DOMNode $descriptionNode */ /** @var DOMNode $descriptionNode */
foreach ($descriptionNodeList as $descriptionNode) { foreach ($descriptionNodeList as $descriptionNode) {
$descriptionNode->parentNode->removeChild($descriptionNode); $descriptionNode->parentNode->removeChild($descriptionNode);
@ -491,7 +493,7 @@ EOF
} }
} }
else { else {
$output->writeln('no descriptions found', OutputInterface::VERBOSITY_VERBOSE); $output->writeln('No existing description found', OutputInterface::VERBOSITY_VERBOSE);
} }
//endregion //endregion
//region Overwrite root file in ZIP //region Overwrite root file in ZIP
@ -524,7 +526,6 @@ EOF
return; return;
} }
/** @noinspection PhpVoidFunctionResultUsedInspection */
if (!$fileArchive->replaceFile( if (!$fileArchive->replaceFile(
$rootFilePathTemp, $rootFilePathTemp,
$rootFileIndex, $rootFileIndex,

Loading…
Cancel
Save