|
| 1 | +import { LICENSES, licenseSlug } from '@/utils/license-utilities' |
| 2 | + |
| 3 | +function minify(data) { |
| 4 | + return data.replace(/ {2,}/gi, '').replace(/\n/gi, '') |
| 5 | +} |
| 6 | + |
| 7 | +export const createXMP = ({ shortName, workUrl = '', workTitle = '', creatorName = '', lang = 'en-US' }) => { |
| 8 | + const slug = licenseSlug(shortName).replace(/-/gi, '_').toUpperCase() |
| 9 | + |
| 10 | + const copyrighted = shortName !== LICENSES.CC0.SHORT |
| 11 | + const xapRights = copyrighted |
| 12 | + ? `<rdf:Description rdf:about='' xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'> |
| 13 | + <xapRights:Marked>true</xapRights:Marked></rdf:Description>` |
| 14 | + : '' |
| 15 | + const xapWorkUrl = workUrl |
| 16 | + ? `<rdf:Description rdf:about='' xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'> |
| 17 | +<xapRights:WebStatement rdf:resource='${workUrl}'/></rdf:Description>` |
| 18 | + : '' |
| 19 | + const xapWorkTitle = workTitle |
| 20 | + ? ` |
| 21 | +<rdf:Description rdf:about='' xmlns:dc='http://purl.org/dc/elements/1.1/'><dc:title><rdf:Alt><rdf:li xml:lang='x-default'> |
| 22 | +${workTitle}</rdf:li><rdf:li xml:lang='${lang}'>${workTitle}</rdf:li></rdf:Alt></dc:title></rdf:Description>` |
| 23 | + : '' |
| 24 | + |
| 25 | + const licenseUrl = LICENSES[slug].URL |
| 26 | + |
| 27 | + const ccLicenseUrl = ` |
| 28 | +<rdf:Description rdf:about='' xmlns:cc='http://creativecommons.org/ns#'><cc:license rdf:resource='${licenseUrl}'/></rdf:Description>` |
| 29 | + |
| 30 | + const ccLicenseNotice = ` |
| 31 | +This work is licensed under <a rel="license noopener noreferrer" target="_blank" href="${licenseUrl}">${LICENSES[slug].FULL}</a>` |
| 32 | + |
| 33 | + const xapRightsUsageTerms = ` |
| 34 | +<rdf:Description rdf:about='' xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'> |
| 35 | +<xapRights:UsageTerms><rdf:Alt><rdf:li xml:lang='${lang}' >${ccLicenseNotice}</rdf:li></rdf:Alt> |
| 36 | +</xapRights:UsageTerms></rdf:Description>` |
| 37 | + |
| 38 | + const xapWebStatement = workUrl |
| 39 | + ? ` |
| 40 | +<rdf:Description rdf:about='' xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'> |
| 41 | +<xapRights:WebStatement rdf:resource='${workUrl}'/></rdf:Description>` |
| 42 | + : '' |
| 43 | + |
| 44 | + const ccAttributionName = creatorName |
| 45 | + ? ` |
| 46 | +<rdf:Description rdf:about='' xmlns:cc='http://creativecommons.org/ns#'> |
| 47 | +<cc:attributionName>${creatorName}</cc:attributionName></rdf:Description>` |
| 48 | + : '' |
| 49 | + // eslint-disable-line quotes |
| 50 | + const xmpData = ` |
| 51 | + <?xpacket begin='' id=''?> |
| 52 | + <x:xmpmeta xmlns:x='adobe:ns:meta/'> |
| 53 | + <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'> |
| 54 | + ${xapRights} |
| 55 | + ${xapWorkUrl} |
| 56 | + ${xapWebStatement} |
| 57 | + ${xapRightsUsageTerms} |
| 58 | + ${xapWorkTitle} |
| 59 | + ${ccLicenseUrl} |
| 60 | + ${ccAttributionName} |
| 61 | + </rdf:RDF> |
| 62 | + </x:xmpmeta> |
| 63 | + <?xpacket end='r'?>` |
| 64 | + // We return minified string to not increase the size of the licensed file |
| 65 | + return minify(xmpData) |
| 66 | +} |
0 commit comments