Skip to content

Commit

Permalink
Support guide.
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed Apr 8, 2023
1 parent d876310 commit 2623da1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Hametuha/HamePub/Oebps/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,14 @@ public function addIdref($id, $liner = 'yes', array $properties = [])
* This `guide` element is not nescesary for ePub 3.0,
* but KF8(Kindle) still requires it.
*
* @see http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.6
* @see https://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.6
* @param string $type
* @param string $href
* @param string $title
*
* @return mixed
* @return \SimpleXMLElement
*/
public function addGuide($type, $href)
public function addGuide($type, $href, $title = '')
{
if (!$this->dom->guide->count()) {
$guide = $this->dom->addChild('guide');
Expand All @@ -203,6 +204,9 @@ public function addGuide($type, $href)
$ref = $guide->addChild('reference');
$ref['type'] = $type;
$ref['href'] = $href;
if ($title) {
$ref['title'] = $title;
}
return $ref;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Hametuha/HamePub/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public function parse($file = 'setting.json', $tmp_dir = '')
if ($this->setting['cover']) {
$factory->addCover($this->setting['cover']);
}
// Set guider if exists.
if (!empty($this->setting['guides'])) {
foreach ($this->setting['guides'] as $guide) {
$factory->opf->addGuide($guide['type'], $guide['href'], $guide['title'] ?? '');
}
}
$factory->opf->putXML();
$factory->container->putXML();
// Save it!
Expand Down

0 comments on commit 2623da1

Please sign in to comment.