From fbc7799b100e288b37bdc5ea1376a36b3d3fb671 Mon Sep 17 00:00:00 2001 From: Harm te Molder Date: Mon, 13 Jan 2025 14:39:32 +0100 Subject: [PATCH 1/7] Do not add chapters for metadata --- src/Helper/EntriesExport.php | 71 +++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php index e05f3af84..0a21ccfac 100644 --- a/src/Helper/EntriesExport.php +++ b/src/Helper/EntriesExport.php @@ -139,16 +139,16 @@ class EntriesExport /* * Start and End of the book */ - $content_start = + $chapterStart = "\n" . "\n" . '' . "\n" - . "wallabag articles book\n" + . "{$this->title}\n" . "\n" . "\n"; - $bookEnd = "\n\n"; + $chapterEnd = "\n\n"; $book = new EPub(EPub::BOOK_VERSION_EPUB3); @@ -159,13 +159,8 @@ class EntriesExport $book->setTitle($this->title); // EPub specification requires BCP47-compliant languages, thus we replace _ with - $book->setLanguage(str_replace('_', '-', $this->language)); - $book->setDescription('Some articles saved on my wallabag'); - $book->setAuthor($this->author, $this->author); - - // I hope this is a non-existent address :) - $book->setPublisher('wallabag', 'wallabag'); - // Strictly not needed as the book date defaults to time(). + $book->setPublisher('wallabag', $this->wallabagUrl); $book->setDate(time()); $book->setSourceURL($this->wallabagUrl); @@ -174,6 +169,10 @@ class EntriesExport $entryIds = []; $entryCount = \count($this->entries); + + if ($entryCount > 1) { + $book->setDescription("{$entryCount} articles saved on my wallabag"); + } $i = 0; /* @@ -184,17 +183,13 @@ class EntriesExport foreach ($this->entries as $entry) { ++$i; - /* - * Front page - * Set if there's only one entry in the given set - */ - if (1 === $entryCount && null !== $entry->getPreviewPicture()) { - $book->setCoverImage($entry->getPreviewPicture()); - } + $internalLink = $this->wallabagUrl . '/view/' . $entry->getId(); foreach ($entry->getTags() as $tag) { $book->setSubject($tag->getLabel()); } + + // use a hash of the original URL plus title as chapter filename inside the Epub $filename = sha1(\sprintf('%s:%s', $entry->getUrl(), $entry->getTitle())); $publishedBy = $entry->getPublishedBy(); @@ -211,26 +206,50 @@ class EntriesExport $readingTime = round($entry->getReadingTime() / $user->getConfig()->getReadingSpeed() * 200); - $titlepage = $content_start . - '

' . $entry->getTitle() . '

' . + if ($entryCount > 1) { + $chapterName = "{$i}. {$entry->getTitle()}"; + $chapter = $chapterStart . "

({$i}/{$entryCount}) {$entry->getTitle()}

"; + } else { + $book->setDescription($entry->getUrl()); + if (null !== $entry->getPreviewPicture()) { + $book->setCoverImage($entry->getPreviewPicture()); + } + $chapterName = $entry->getTitle(); + $chapter = $chapterStart . "

{$entry->getTitle()}

"; + } + + if (null !== $entry->getPreviewPicture()) { + // TODO Try to re-use the cover image from before + $chapter = $chapter . "getPreviewPicture()}\">"; + } + + // TODO Add translations for internal and public links + $chapter = $chapter . '
' . '
' . $this->translator->trans('entry.view.published_by') . '
' . $authors . '
' . '
' . $this->translator->trans('entry.metadata.published_on') . '
' . $publishedDate . '
' . - '
' . $this->translator->trans('entry.metadata.reading_time') . '
' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $readingTime]) . '
' . '
' . $this->translator->trans('entry.metadata.added_on') . '
' . $entry->getCreatedAt()->format('Y-m-d') . '
' . + '
' . $this->translator->trans('entry.metadata.reading_time') . '
' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $readingTime]) . '
' . '
' . $this->translator->trans('entry.metadata.address') . '
' . $entry->getUrl() . '
' . - '
' . - $bookEnd; - $book->addChapter("Entry {$i} of {$entryCount}", "{$filename}_cover.html", $titlepage, true, EPub::EXTERNAL_REF_ADD); - $chapter = $content_start . $entry->getContent() . $bookEnd; + '
Internal link
' . $internalLink . '
'; + + if ($entry->isPublic()) { + $publicLink = $this->wallabagUrl . '/share/' . $entry->getUid(); + $chapter = $chapter . '
Public link
' . $publicLink . '
'; + } + + $chapter = $chapter . '' . + "

{$entry->getTitle()}

" . + $entry->getContent() . + $chapterEnd; $entryIds[] = $entry->getId(); - $book->addChapter($entry->getTitle(), "{$filename}.html", $chapter, true, EPub::EXTERNAL_REF_ADD); + $book->addChapter($chapterName, "{$filename}.html", $chapter, true, EPub::EXTERNAL_REF_ADD); } - $book->addChapter('Notices', 'Cover2.html', $content_start . $this->getExportInformation('PHPePub') . $bookEnd); + $book->addChapter('Notices', 'CoverBack.xhtml', $chapterStart . $this->getExportInformation('PHPePub') . $chapterEnd); - // Could also be the ISBN number, prefered for published books, or a UUID. + // Set identifier to a hash of the wallabag server URL plus comma-separated entry IDs $hash = sha1(\sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds))); $book->setIdentifier(\sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI); From 36edaa809856fa5d60aafbb7d78c38123b11ec01 Mon Sep 17 00:00:00 2001 From: Harm te Molder Date: Mon, 13 Jan 2025 15:45:49 +0100 Subject: [PATCH 2/7] Do not add Guide chapter for CoverPage --- src/Helper/EntriesExport.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php index 0a21ccfac..479ff5e25 100644 --- a/src/Helper/EntriesExport.php +++ b/src/Helper/EntriesExport.php @@ -220,12 +220,11 @@ class EntriesExport if (null !== $entry->getPreviewPicture()) { // TODO Try to re-use the cover image from before - $chapter = $chapter . "getPreviewPicture()}\">"; + $chapter .= "getPreviewPicture()}\">"; } // TODO Add translations for internal and public links - $chapter = $chapter . - '
' . + $chapter .= '
' . '
' . $this->translator->trans('entry.view.published_by') . '
' . $authors . '
' . '
' . $this->translator->trans('entry.metadata.published_on') . '
' . $publishedDate . '
' . '
' . $this->translator->trans('entry.metadata.added_on') . '
' . $entry->getCreatedAt()->format('Y-m-d') . '
' . @@ -235,16 +234,16 @@ class EntriesExport if ($entry->isPublic()) { $publicLink = $this->wallabagUrl . '/share/' . $entry->getUid(); - $chapter = $chapter . '
Public link
' . $publicLink . '
'; + $chapter .= '
Public link
' . $publicLink . '
'; } - $chapter = $chapter . '
' . + $chapter .= '
' . "

{$entry->getTitle()}

" . $entry->getContent() . $chapterEnd; $entryIds[] = $entry->getId(); - $book->addChapter($chapterName, "{$filename}.html", $chapter, true, EPub::EXTERNAL_REF_ADD); + $book->addChapter($chapterName, "{$filename}.xhtml", $chapter, true, EPub::EXTERNAL_REF_ADD); } $book->addChapter('Notices', 'CoverBack.xhtml', $chapterStart . $this->getExportInformation('PHPePub') . $chapterEnd); @@ -253,6 +252,9 @@ class EntriesExport $hash = sha1(\sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds))); $book->setIdentifier(\sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI); + // Do not add "Guide" chapter for "CoverPage" + $book->setisReferencesAddedToToc(false); + return Response::create( $book->getBook(), 200, From d731cfc0cb28e168adcd5f08a2e51d8402d5aada Mon Sep 17 00:00:00 2001 From: Harm te Molder Date: Thu, 16 Jan 2025 09:54:04 +0100 Subject: [PATCH 3/7] Use domain name as author instead of "Unknown" --- src/Helper/EntriesExport.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php index 479ff5e25..695d7b268 100644 --- a/src/Helper/EntriesExport.php +++ b/src/Helper/EntriesExport.php @@ -192,8 +192,11 @@ class EntriesExport // use a hash of the original URL plus title as chapter filename inside the Epub $filename = sha1(\sprintf('%s:%s', $entry->getUrl(), $entry->getTitle())); + $authors = $entry->getDomainName(); + if (empty($authors)) { // TODO Test this + $authors = $this->translator->trans('export.unknown'); + } $publishedBy = $entry->getPublishedBy(); - $authors = $this->translator->trans('export.unknown'); if (!empty($publishedBy)) { $authors = implode(',', $publishedBy); } From cc26cf50010662627337f34983d6240dc416aabd Mon Sep 17 00:00:00 2001 From: Harm te Molder Date: Thu, 21 Aug 2025 14:14:51 +0200 Subject: [PATCH 4/7] Check for empty string in published_by array as well --- src/Helper/EntriesExport.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php index 30ecc94fb..273332ec9 100644 --- a/src/Helper/EntriesExport.php +++ b/src/Helper/EntriesExport.php @@ -86,17 +86,20 @@ class EntriesExport */ public function updateAuthor($method) { - if ('entry' !== $method) { + if ($method !== 'entry') { $this->author = 'Various authors'; return $this; } - $this->author = $this->entries[0]->getDomainName(); - $publishedBy = $this->entries[0]->getPublishedBy(); - if (!empty($publishedBy)) { + $domainName = $this->entries[0]->getDomainName(); + if (!empty($publishedBy) && !empty($publishedBy[0])) { $this->author = implode(', ', $publishedBy); + } elseif (!empty($domainName)) { + $this->author = $domainName; + } else { + $this->author = $this->translator->trans('export.unknown'); } return $this; @@ -188,13 +191,14 @@ class EntriesExport // use a hash of the original URL plus title as chapter filename inside the Epub $filename = sha1(\sprintf('%s:%s', $entry->getUrl(), $entry->getTitle())); - $authors = $entry->getDomainName(); - if (empty($authors)) { // TODO Test this - $authors = $this->translator->trans('export.unknown'); - } $publishedBy = $entry->getPublishedBy(); - if (!empty($publishedBy)) { - $authors = implode(',', $publishedBy); + $domainName = $entry->getDomainName(); + if (!empty($publishedBy) && !empty($publishedBy[0])) { + $authors = implode(', ', $publishedBy); + } elseif (!empty($domainName)) { + $authors = $domainName; + } else { + $authors = $this->translator->trans('export.unknown'); } $publishedAt = $entry->getPublishedAt(); @@ -295,7 +299,7 @@ class EntriesExport $publishedBy = $entry->getPublishedBy(); $authors = $this->translator->trans('export.unknown'); - if (!empty($publishedBy)) { + if (!empty($publishedBy) && !empty($publishedBy[0])) { $authors = implode(',', $publishedBy); } From 86a881b3588a5fad0c7848deaad353671bbfa43c Mon Sep 17 00:00:00 2001 From: Harm te Molder Date: Thu, 21 Aug 2025 14:36:17 +0200 Subject: [PATCH 5/7] Use existing translation for "Public link" --- src/Helper/EntriesExport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php index 273332ec9..14bbe253c 100644 --- a/src/Helper/EntriesExport.php +++ b/src/Helper/EntriesExport.php @@ -86,7 +86,7 @@ class EntriesExport */ public function updateAuthor($method) { - if ($method !== 'entry') { + if ('entry' !== $method) { $this->author = 'Various authors'; return $this; @@ -237,7 +237,7 @@ class EntriesExport if ($entry->isPublic()) { $publicLink = $this->wallabagUrl . '/share/' . $entry->getUid(); - $chapter .= '
Public link
' . $publicLink . '
'; + $chapter .= '
' . $this->translator->trans('entry.filters.is_public_help') . '
' . $publicLink . '
'; } $chapter .= '' . From 203d77b6da6638f429c8526a09f4d0aa399f6ea4 Mon Sep 17 00:00:00 2001 From: Harm te Molder Date: Thu, 21 Aug 2025 14:43:58 +0200 Subject: [PATCH 6/7] Add EN and FR translations for internal and public links --- src/Helper/EntriesExport.php | 5 ++--- translations/messages.en.yml | 2 ++ translations/messages.fr.yml | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php index 14bbe253c..e749d3200 100644 --- a/src/Helper/EntriesExport.php +++ b/src/Helper/EntriesExport.php @@ -226,18 +226,17 @@ class EntriesExport $chapter .= "getPreviewPicture()}\">"; } - // TODO Add translations for internal and public links $chapter .= '
' . '
' . $this->translator->trans('entry.view.published_by') . '
' . $authors . '
' . '
' . $this->translator->trans('entry.metadata.published_on') . '
' . $publishedDate . '
' . '
' . $this->translator->trans('entry.metadata.added_on') . '
' . $entry->getCreatedAt()->format('Y-m-d') . '
' . '
' . $this->translator->trans('entry.metadata.reading_time') . '
' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $readingTime]) . '
' . '
' . $this->translator->trans('entry.metadata.address') . '
' . $entry->getUrl() . '
' . - '
Internal link
' . $internalLink . '
'; + '
' . $this->translator->trans('entry.metadata.internal_link') . '
' . $internalLink . '
'; if ($entry->isPublic()) { $publicLink = $this->wallabagUrl . '/share/' . $entry->getUid(); - $chapter .= '
' . $this->translator->trans('entry.filters.is_public_help') . '
' . $publicLink . '
'; + $chapter .= '
' . $this->translator->trans('entry.metadata.public_link') . '
' . $publicLink . '
'; } $chapter .= '
' . diff --git a/translations/messages.en.yml b/translations/messages.en.yml index fcf566acf..4e4598403 100644 --- a/translations/messages.en.yml +++ b/translations/messages.en.yml @@ -336,6 +336,8 @@ entry: reading_time: Estimated reading time reading_time_minutes_short: '%readingTime% min' address: Address + internal_link: Internal link + public_link: Public link added_on: Added on published_on: "Published on" about: diff --git a/translations/messages.fr.yml b/translations/messages.fr.yml index 0f9017d23..ea63affa6 100644 --- a/translations/messages.fr.yml +++ b/translations/messages.fr.yml @@ -336,6 +336,8 @@ entry: reading_time: Durée de lecture estimée reading_time_minutes_short: '%readingTime% min' address: Adresse + internal_link: Lien interne + public_link: Lien public added_on: Ajouté le published_on: Publié le about: From 6e61a4632a0a92fdc8eec640c06b21a6252c1103 Mon Sep 17 00:00:00 2001 From: Harm te Molder Date: Thu, 21 Aug 2025 15:10:28 +0200 Subject: [PATCH 7/7] Only add preview picture to body if not already used as cover image --- src/Helper/EntriesExport.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php index e749d3200..5fb181fda 100644 --- a/src/Helper/EntriesExport.php +++ b/src/Helper/EntriesExport.php @@ -212,6 +212,9 @@ class EntriesExport if ($entryCount > 1) { $chapterName = "{$i}. {$entry->getTitle()}"; $chapter = $chapterStart . "

({$i}/{$entryCount}) {$entry->getTitle()}

"; + if (null !== $entry->getPreviewPicture()) { + $chapter .= "getPreviewPicture()}\">"; + } } else { $book->setDescription($entry->getUrl()); if (null !== $entry->getPreviewPicture()) { @@ -221,10 +224,6 @@ class EntriesExport $chapter = $chapterStart . "

{$entry->getTitle()}

"; } - if (null !== $entry->getPreviewPicture()) { - // TODO Try to re-use the cover image from before - $chapter .= "getPreviewPicture()}\">"; - } $chapter .= '
' . '
' . $this->translator->trans('entry.view.published_by') . '
' . $authors . '
' .