git.iko.soy/typeable/pandoc
on master help sign in
ePub writer: `belongs-to-collection` metadata (#7063)
commitb79aba6ea1ecb6a1f619128638369ef47f64d26d authorNick Berendsen <58348935+Desbeers@users.noreply.github.com> dateWed 3 Feb 2021, 18:00 (6 years ago) parent4de9edb
2 files changed+67−41
MANUAL.txt+9 src/Text/Pandoc/Writers/EPUB.hs+58−41
MANUAL.txt+9
@@ -5931,6 +5931,15 @@ The following fields are recognized:
59315931
59325932`rights`
59335933 ~ A string value.
5934+
5935+`belongs-to-collection`
5936+ ~ A string value. identifies the name of a collection to which
5937+ the EPUB Publication belongs.
5938+
5939+`group-position`
5940+ ~ The `group-position` field indicates the numeric position in which
5941+ the EPUB Publication belongs relative to other works belonging to
5942+ the same `belongs-to-collection` field.
59345943
59355944`cover-image`
59365945 ~ A string value (path to cover image).
src/Text/Pandoc/Writers/EPUB.hs+58−41
@@ -74,26 +74,28 @@ data EPUBState = EPUBState {
7474type E m = StateT EPUBState m
7575
7676data EPUBMetadata = EPUBMetadata{
77− epubIdentifier :: [Identifier]
78− , epubTitle :: [Title]
79− , epubDate :: [Date]
80− , epubLanguage :: String
81− , epubCreator :: [Creator]
82− , epubContributor :: [Creator]
83− , epubSubject :: [String]
84− , epubDescription :: Maybe String
85− , epubType :: Maybe String
86− , epubFormat :: Maybe String
87− , epubPublisher :: Maybe String
88− , epubSource :: Maybe String
89− , epubRelation :: Maybe String
90− , epubCoverage :: Maybe String
91− , epubRights :: Maybe String
92− , epubCoverImage :: Maybe String
93− , epubStylesheets :: [FilePath]
94− , epubPageDirection :: Maybe ProgressionDirection
95− , epubIbooksFields :: [(String, String)]
96− , epubCalibreFields :: [(String, String)]
77+ epubIdentifier :: [Identifier]
78+ , epubTitle :: [Title]
79+ , epubDate :: [Date]
80+ , epubLanguage :: String
81+ , epubCreator :: [Creator]
82+ , epubContributor :: [Creator]
83+ , epubSubject :: [String]
84+ , epubDescription :: Maybe String
85+ , epubType :: Maybe String
86+ , epubFormat :: Maybe String
87+ , epubPublisher :: Maybe String
88+ , epubSource :: Maybe String
89+ , epubRelation :: Maybe String
90+ , epubCoverage :: Maybe String
91+ , epubRights :: Maybe String
92+ , epubBelongsToCollection :: Maybe String
93+ , epubGroupPosition :: Maybe String
94+ , epubCoverImage :: Maybe String
95+ , epubStylesheets :: [FilePath]
96+ , epubPageDirection :: Maybe ProgressionDirection
97+ , epubIbooksFields :: [(String, String)]
98+ , epubCalibreFields :: [(String, String)]
9799 } deriving Show
98100
99101data Date = Date{
@@ -235,6 +237,8 @@ addMetadataFromXML e@(Element (QName name _ (Just "dc")) attrs _ _) md
235237 | name == "relation" = md { epubRelation = Just $ strContent e }
236238 | name == "coverage" = md { epubCoverage = Just $ strContent e }
237239 | name == "rights" = md { epubRights = Just $ strContent e }
240+ | name == "belongs-to-collection" = md { epubBelongsToCollection = Just $ strContent e }
241+ | name == "group-position" = md { epubGroupPosition = Just $ strContent e }
238242 | otherwise = md
239243 where getAttr n = lookupAttr (opfName n) attrs
240244addMetadataFromXML e@(Element (QName "meta" _ _) attrs _ _) md =
@@ -313,26 +317,28 @@ simpleList s meta =
313317
314318metadataFromMeta :: WriterOptions -> Meta -> EPUBMetadata
315319metadataFromMeta opts meta = EPUBMetadata{
316− epubIdentifier = identifiers
317− , epubTitle = titles
318− , epubDate = date
319− , epubLanguage = language
320− , epubCreator = creators
321− , epubContributor = contributors
322− , epubSubject = subjects
323− , epubDescription = description
324− , epubType = epubtype
325− , epubFormat = format
326− , epubPublisher = publisher
327− , epubSource = source
328− , epubRelation = relation
329− , epubCoverage = coverage
330− , epubRights = rights
331− , epubCoverImage = coverImage
332− , epubStylesheets = stylesheets
333− , epubPageDirection = pageDirection
334− , epubIbooksFields = ibooksFields
335− , epubCalibreFields = calibreFields
320+ epubIdentifier = identifiers
321+ , epubTitle = titles
322+ , epubDate = date
323+ , epubLanguage = language
324+ , epubCreator = creators
325+ , epubContributor = contributors
326+ , epubSubject = subjects
327+ , epubDescription = description
328+ , epubType = epubtype
329+ , epubFormat = format
330+ , epubPublisher = publisher
331+ , epubSource = source
332+ , epubRelation = relation
333+ , epubCoverage = coverage
334+ , epubRights = rights
335+ , epubBelongsToCollection = belongsToCollection
336+ , epubGroupPosition = groupPosition
337+ , epubCoverImage = coverImage
338+ , epubStylesheets = stylesheets
339+ , epubPageDirection = pageDirection
340+ , epubIbooksFields = ibooksFields
341+ , epubCalibreFields = calibreFields
336342 }
337343 where identifiers = getIdentifier meta
338344 titles = getTitle meta
@@ -350,6 +356,8 @@ metadataFromMeta opts meta = EPUBMetadata{
350356 relation = metaValueToString <$> lookupMeta "relation" meta
351357 coverage = metaValueToString <$> lookupMeta "coverage" meta
352358 rights = metaValueToString <$> lookupMeta "rights" meta
359+ belongsToCollection = metaValueToString <$> lookupMeta "belongs-to-collection" meta
360+ groupPosition = metaValueToString <$> lookupMeta "group-position" meta
353361 coverImage =
354362 (TS.unpack <$> lookupContext "epub-cover-image"
355363 (writerVariables opts))
@@ -931,7 +939,7 @@ metadataElement version md currentTime =
931939 ++ descriptionNodes ++ typeNodes ++ formatNodes
932940 ++ publisherNodes ++ sourceNodes ++ relationNodes
933941 ++ coverageNodes ++ rightsNodes ++ coverImageNodes
934− ++ modifiedNodes
942+ ++ modifiedNodes ++ belongsToCollectionNodes
935943 withIds base f = concat . zipWith f (map (\x -> base ++ ('-' : show x))
936944 ([1..] :: [Int]))
937945 identifierNodes = withIds "epub-id" toIdentifierNode $
@@ -970,6 +978,15 @@ metadataElement version md currentTime =
970978 $ epubCoverImage md
971979 modifiedNodes = [ unode "meta" ! [("property", "dcterms:modified")] $
972980 showDateTimeISO8601 currentTime | version == EPUB3 ]
981+ belongsToCollectionNodes =
982+ maybe []
983+ (\belongsToCollection -> (unode "meta" ! [("property", "belongs-to-collection"), ("id", "epub-id-1")] $ belongsToCollection )
984+ :
985+ [unode "meta" ! [("refines", "#epub-id-1"), ("property", "collection-type")] $ ("series" :: String) ])
986+ (epubBelongsToCollection md)++
987+ maybe []
988+ (\groupPosition -> [unode "meta" ! [("refines", "#epub-id-1"), ("property", "group-position")] $ groupPosition ])
989+ (epubGroupPosition md)
973990 dcTag n s = unode ("dc:" ++ n) s
974991 dcTag' n s = [dcTag n s]
975992 toIdentifierNode id' (Identifier txt scheme)