Skip to content

Commit

Permalink
#59 PDFs not prioritized for full body text
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhanson committed Nov 15, 2024
1 parent 422737e commit 9283455
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions JatsTemplatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use HTMLPurifier_Config;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
use PKP\galley\Galley;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use PKP\plugins\PluginRegistry;
Expand Down Expand Up @@ -325,10 +326,24 @@ function toXml(&$record, $format = null) {
$text = '';
$galleys = $article->getGalleys();

// Give precedence to HTML galleys, as they're quickest to parse
usort($galleys, function($a, $b) {
return $a->getFileType() == 'text/html'?-1:1;
});
// Get HTML galleys for top of list, as they're quickest to parse
// PDFs have second-highest priority over other file types
$items = array_reduce($galleys, function(array $carry, Galley $galley) {
$fileType = $galley->getFileType();

switch ($fileType) {
case 'text/html':
$carry['html'][] = $galley;
break;
case 'application/pdf':
$carry['pdf'][] = $galley;
break;
default:
$carry['other'][] = $galley;
}
return $carry;
}, ['html' => [], 'pdf' => [], 'other' => []]);
$galleys = array_merge($items['html'], $items['pdf'], $items['other']);

// Provide the full-text.
$fileService = Services::get('file');
Expand Down

0 comments on commit 9283455

Please sign in to comment.