|
| 1 | +/* eslint-disable indent, quotes */ |
| 2 | +import { LICENSES, licenseSlug } from '@/utils/license-utilities' |
| 3 | + |
| 4 | +/** The xmp metadata is structured in accordance with the Adobe XMP specifications from 2012: |
| 5 | +https://wwwimages2.adobe.com/content/dam/acom/en/devnet/xmp/pdfs/XMP%20SDK%20Release%20cc-2016-08/XMPSpecificationPart1.pdf |
| 6 | +
|
| 7 | +The following data is written into the xmp file: |
| 8 | +
|
| 9 | +xapRights:WebStatement: A Web URL for a statement of the ownership and usage rights for this resource. |
| 10 | + Uses the value of the 'Link to Work' field from the Attribution details form. |
| 11 | +xapRights:Marked: Indicates that this is a public-domain or CC0 resource if false. Otherwise, one of the 6 CC licenses. |
| 12 | +xapRights:Owner: A list of legal owners of the resource. |
| 13 | + Uses the value of the 'Creator of Work' field from the Attribution details form. |
| 14 | +xapRights:UsageTerms: A collection of text instructions on how a resource can be legally used, given in a variety of languages. |
| 15 | + Uses license statement with the link to the license deed, with '<>"' characters escaped. |
| 16 | +dc:title: A name or title given to the resource, by which it is formally known, given in various languages. |
| 17 | + Uses the value of the 'Title of Work' field from the Attribution details form. |
| 18 | +cc:license: the link to the CC license deed. |
| 19 | +cc:attributionName |
| 20 | + Uses the value of the 'Creator of Work' field from the Attribution details form. |
| 21 | + */ |
| 22 | + |
| 23 | +export const createXMP = ({ shortName, workUrl = '', workTitle = '', creatorName = '', lang = 'en-US' }) => { |
| 24 | + const slug = licenseSlug(shortName).replace(/-/gi, '_').toUpperCase() |
| 25 | + |
| 26 | + const licenseUrl = LICENSES[slug].URL |
| 27 | + const licenseFullName = LICENSES[slug].FULL |
| 28 | + |
| 29 | + const ccLicenseNotice = `This work is licensed under <a href="${licenseUrl}">${licenseFullName}</a>` |
| 30 | + .replace(/</gi, '<') |
| 31 | + .replace(/>/gi, '>') |
| 32 | + .replace(/"/gi, '"') |
| 33 | + |
| 34 | + const isLicensed = shortName !== LICENSES.CC0.SHORT ? 'True' : 'False' |
| 35 | + |
| 36 | + return (`<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?> |
| 37 | +<x:xmpmeta xmlns:x='adobe:ns:meta/'> |
| 38 | + <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' |
| 39 | + xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/' |
| 40 | + xmlns:cc='http://creativecommons.org/ns#'${workTitle |
| 41 | + ? `xmlns:dc='http://purl.org/dc/elements/1.1/'` |
| 42 | + : ''}> |
| 43 | + <rdf:Description rdf:about=''> |
| 44 | + ${`<xapRights:Marked>${isLicensed}</xapRights:Marked>`}${creatorName |
| 45 | + ? ` |
| 46 | + <xapRights:Owner> |
| 47 | + <rdf:Bag> |
| 48 | + <rdf:li>${creatorName}</rdf:li> |
| 49 | + </rdf:Bag> |
| 50 | + </xapRights:Owner>` |
| 51 | + : ''}${workUrl |
| 52 | + ? ` |
| 53 | + <xapRights:WebStatement rdf:resource='${workUrl}'/>` |
| 54 | + : ''} |
| 55 | + <xapRights:UsageTerms> |
| 56 | + <rdf:Alt> |
| 57 | + <rdf:li xml:lang='x-default'>${ccLicenseNotice}</rdf:li> |
| 58 | + <rdf:li xml:lang='${lang}' >${ccLicenseNotice}</rdf:li> |
| 59 | + </rdf:Alt> |
| 60 | + </xapRights:UsageTerms> |
| 61 | + <cc:license rdf:resource='${licenseUrl}'/>${creatorName |
| 62 | + ? ` |
| 63 | + <cc:attributionName>${creatorName}</cc:attributionName>` |
| 64 | + : ''}${workTitle |
| 65 | + ? ` |
| 66 | + <dc:title> |
| 67 | + <rdf:Alt> |
| 68 | + <rdf:li xml:lang='x-default'>${workTitle}</rdf:li> |
| 69 | + <rdf:li xml:lang='${lang}'>${workTitle}</rdf:li> |
| 70 | + </rdf:Alt> |
| 71 | + </dc:title>` |
| 72 | + : ''} |
| 73 | + </rdf:Description> |
| 74 | + </rdf:RDF> |
| 75 | +</x:xmpmeta> |
| 76 | +<?xpacket end='r'?>`) |
| 77 | +} |
0 commit comments