mirror of
https://github.com/standardebooks/web.git
synced 2025-07-10 00:30:28 -04:00
Further improve RDFa metadata
This commit is contained in:
parent
bbb35911cd
commit
d714971e06
3 changed files with 74 additions and 22 deletions
|
@ -297,7 +297,7 @@ class Ebook{
|
|||
// If we added an illustrator who is also the translator, remove the illustrator credit so the name doesn't appear twice
|
||||
foreach($this->Illustrators as $key => $illustrator){
|
||||
foreach($this->Translators as $translator){
|
||||
if($translator->Name == $c->Name){
|
||||
if($translator->Name == $illustrator->Name){
|
||||
unset($this->Illustrators[$key]);
|
||||
break;
|
||||
}
|
||||
|
@ -427,18 +427,18 @@ class Ebook{
|
|||
// Put together the full contributor string.
|
||||
$titleContributors = '';
|
||||
if(sizeof($this->Contributors) > 0){
|
||||
$titleContributors .= '. With ' . $this->GenerateContributorList($this->Contributors);
|
||||
$this->ContributorsHtml .= ' with ' . $this->GenerateContributorList($this->Contributors) . ';';
|
||||
$titleContributors .= '. With ' . $this->GenerateContributorList($this->Contributors, false);
|
||||
$this->ContributorsHtml .= ' with ' . $this->GenerateContributorList($this->Contributors, false) . ';';
|
||||
}
|
||||
|
||||
if(sizeof($this->Translators) > 0){
|
||||
$titleContributors .= '. Translated by ' . $this->GenerateContributorList($this->Translators);
|
||||
$this->ContributorsHtml .= ' translated by ' . $this->GenerateContributorList($this->Translators) . ';';
|
||||
$titleContributors .= '. Translated by ' . $this->GenerateContributorList($this->Translators, false);
|
||||
$this->ContributorsHtml .= ' translated by ' . $this->GenerateContributorList($this->Translators, false) . ';';
|
||||
}
|
||||
|
||||
if(sizeof($this->Illustrators) > 0){
|
||||
$titleContributors .= '. Illustrated by ' . $this->GenerateContributorList($this->Illustrators);
|
||||
$this->ContributorsHtml .= ' illustrated by ' . $this->GenerateContributorList($this->Illustrators) . ';';
|
||||
$titleContributors .= '. Illustrated by ' . $this->GenerateContributorList($this->Illustrators, false);
|
||||
$this->ContributorsHtml .= ' illustrated by ' . $this->GenerateContributorList($this->Illustrators, false) . ';';
|
||||
}
|
||||
|
||||
if($this->ContributorsHtml !== null){
|
||||
|
@ -449,7 +449,7 @@ class Ebook{
|
|||
}
|
||||
}
|
||||
|
||||
$this->AuthorsHtml = $this->GenerateContributorList($this->Authors);
|
||||
$this->AuthorsHtml = $this->GenerateContributorList($this->Authors, true);
|
||||
|
||||
// Now the complete title with credits.
|
||||
$this->TitleWithCreditsHtml = Formatter::ToPlainText($this->Title) . ', by ' . str_replace('&', '&', $this->AuthorsHtml . $titleContributors);
|
||||
|
@ -610,12 +610,13 @@ class Ebook{
|
|||
|
||||
/**
|
||||
* @param array<Contributor> $contributors
|
||||
* @param bool $includeRdfa
|
||||
*/
|
||||
private function GenerateContributorList(array $contributors): string{
|
||||
private function GenerateContributorList(array $contributors, bool $includeRdfa): string{
|
||||
$string = '';
|
||||
$i = 0;
|
||||
foreach($contributors as $contributor){
|
||||
|
||||
foreach($contributors as $contributor){
|
||||
$role = 'schema:contributor';
|
||||
switch($contributor->MarcRole){
|
||||
case 'trl':
|
||||
|
@ -627,22 +628,32 @@ class Ebook{
|
|||
}
|
||||
|
||||
if($contributor->WikipediaUrl){
|
||||
$string .= '<a property="' . $role . '" typeof="schema:Person" href="' . Formatter::ToPlainText($contributor->WikipediaUrl) .'"><span property="schema:name">' . Formatter::ToPlainText($contributor->Name) . '</span>';
|
||||
if($includeRdfa){
|
||||
$string .= '<a property="' . $role . '" typeof="schema:Person" href="' . Formatter::ToPlainText($contributor->WikipediaUrl) .'"><span property="schema:name">' . Formatter::ToPlainText($contributor->Name) . '</span>';
|
||||
|
||||
if($contributor->NacoafUrl){
|
||||
$string .= '<meta property="schema:sameAs" content="' . Formatter::ToPlainText($contributor->NacoafUrl) . '"/>';
|
||||
if($contributor->NacoafUrl){
|
||||
$string .= '<meta property="schema:sameAs" content="' . Formatter::ToPlainText($contributor->NacoafUrl) . '"/>';
|
||||
}
|
||||
}
|
||||
else{
|
||||
$string .= '<a href="' . Formatter::ToPlainText($contributor->WikipediaUrl) .'">' . Formatter::ToPlainText($contributor->Name);
|
||||
}
|
||||
|
||||
$string .= '</a>';
|
||||
}
|
||||
else{
|
||||
$string .= '<span property="' . $role . '" typeof="schema:Person"><span property="schema:name">' . Formatter::ToPlainText($contributor->Name) . '</span>';
|
||||
if($includeRdfa){
|
||||
$string .= '<span property="' . $role . '" typeof="schema:Person"><span property="schema:name">' . Formatter::ToPlainText($contributor->Name) . '</span>';
|
||||
|
||||
if($contributor->NacoafUrl){
|
||||
$string .= '<meta property="schema:sameAs" content="' . Formatter::ToPlainText($contributor->NacoafUrl) . '"/>';
|
||||
if($contributor->NacoafUrl){
|
||||
$string .= '<meta property="schema:sameAs" content="' . Formatter::ToPlainText($contributor->NacoafUrl) . '"/>';
|
||||
}
|
||||
|
||||
$string .= '</span>';
|
||||
}
|
||||
else{
|
||||
$string .= Formatter::ToPlainText($contributor->Name);
|
||||
}
|
||||
|
||||
$string .= '</span>';
|
||||
}
|
||||
|
||||
if($i == sizeof($contributors) - 2 && sizeof($contributors) > 2){
|
||||
|
@ -661,6 +672,46 @@ class Ebook{
|
|||
return $string;
|
||||
}
|
||||
|
||||
public function GenerateContributorsRdfa(): string{
|
||||
$string = '';
|
||||
$i = 0;
|
||||
|
||||
foreach($this->Translators as $contributor){
|
||||
$role = 'schema:contributor';
|
||||
switch($contributor->MarcRole){
|
||||
case 'trl':
|
||||
$role = 'schema:translator';
|
||||
break;
|
||||
case 'ill':
|
||||
$role = 'schema:illustrator';
|
||||
break;
|
||||
}
|
||||
|
||||
if($contributor->WikipediaUrl){
|
||||
$string .= '<div property="' . $role . '" typeof="schema:Person" resource="/contributors/' . Formatter::MakeUrlSafe($contributor->Name) .'">' . "\n";
|
||||
}
|
||||
else{
|
||||
$string .= '<div property="' . $role . '" typeof="schema:Person">' . "\n";
|
||||
}
|
||||
|
||||
$string .= '<meta property="schema:name" content="' . Formatter::ToPlainText($contributor->Name) . '"/>' . "\n";
|
||||
|
||||
if($contributor->WikipediaUrl){
|
||||
$string .= '<meta property="schema:sameAs" content="' . Formatter::ToPlainText($contributor->WikipediaUrl) . '"/>' . "\n";
|
||||
}
|
||||
|
||||
if($contributor->NacoafUrl){
|
||||
$string .= '<meta property="schema:sameAs" content="' . Formatter::ToPlainText($contributor->NacoafUrl) . '"/>' . "\n";
|
||||
}
|
||||
|
||||
$string .= '</div>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
private function NullIfEmpty($elements): ?string{
|
||||
if($elements === false){
|
||||
return null;
|
||||
|
|
|
@ -150,7 +150,7 @@ require_once('Core.php');
|
|||
<img src="/images/masthead/portrait.svg" role="presentation" alt=""/>
|
||||
<p>Anonymous × 3</p>
|
||||
</li>
|
||||
<? if(false){ ?>
|
||||
<? /*
|
||||
<li>
|
||||
<picture>
|
||||
<source srcset="/images/masthead/firstname-lastname@2x.avif 2x, /images/masthead/firstname-lastname.avif 1x" type="image/avif"/>
|
||||
|
@ -159,7 +159,7 @@ require_once('Core.php');
|
|||
</picture>
|
||||
<p>Firstname Lastname</p>
|
||||
</li>
|
||||
<? } ?>
|
||||
*/ ?>
|
||||
</ol>
|
||||
</section>
|
||||
</section>
|
||||
|
|
|
@ -90,6 +90,7 @@ catch(\Exception $ex){
|
|||
<span property="schema:name"><?= Formatter::ToPlainText($author->Name) ?></span>
|
||||
<meta property="schema:url" content="<?= SITE_URL . Formatter::ToPlainText($ebook->AuthorsUrl) ?>"/>
|
||||
<? if($author->NacoafUrl){ ?><meta property="schema:sameAs" content="<?= Formatter::ToPlainText($author->NacoafUrl) ?>"/><? } ?>
|
||||
<? if($author->WikipediaUrl){ ?><meta property="schema:sameAs" content="<?= Formatter::ToPlainText($author->WikipediaUrl) ?>"/><? } ?>
|
||||
</a>
|
||||
</h2>
|
||||
<? } ?>
|
||||
|
@ -138,10 +139,9 @@ catch(\Exception $ex){
|
|||
</section>
|
||||
|
||||
<? if($ebook->HasDownloads){ ?>
|
||||
<section id="read-free" property="schema:workExample" typeof="schema:Book">
|
||||
<section id="read-free" property="schema:workExample" typeof="schema:Book" resource="<?= Formatter::ToPlainText($ebook->Url) ?>/downloads">
|
||||
<meta property="schema:bookFormat" content="http://schema.org/EBook"/>
|
||||
<meta property="schema:url" content="<?= Formatter::ToPlainText(SITE_URL . $ebook->Url) ?>"/>
|
||||
<meta property="schema:identifier" content="<?= Formatter::ToPlainText(SITE_URL . $ebook->Url) ?>"/>
|
||||
<meta property="schema:license" content="https://creativecommons.org/publicdomain/zero/1.0/"/>
|
||||
<div property="schema:publisher" typeof="schema:Organization">
|
||||
<meta property="schema:name" content="Standard Ebooks"/>
|
||||
|
@ -168,6 +168,7 @@ catch(\Exception $ex){
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?= $ebook->GenerateContributorsRdfa() ?>
|
||||
<h2>Read free</h2>
|
||||
<p class="us-pd-warning">This ebook is only thought to be free of copyright restrictions in the United States. It may still be under copyright in other countries. If you’re not located in the United States, you must check your local laws to verify that the contents of this ebook are free of copyright restrictions in the country you’re located in before downloading or using this ebook.</p>
|
||||
<section id="download">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue