1
+ /* eslint-disable indent, quotes */
1
2
import { LICENSES , licenseSlug } from '@/utils/license-utilities'
2
3
3
4
/** The xmp metadata is structured in accordance with the Adobe XMP specifications from 2012:
@@ -19,102 +20,58 @@ cc:attributionName
19
20
Uses the value of the 'Creator of Work' field from the Attribution details form.
20
21
*/
21
22
22
- // To make the values of these variables human-readable, and format the resulting document correctly,
23
- // we use the backtick-formatted strings, but remove the '\n' character in the beginning of the values
24
- const XAP_WEB_STATEMENT = `
25
- <xapRights:WebStatement rdf:resource='{workUrlTemplate}'/>` . slice ( 1 )
26
-
27
- const XAP_MARKED = `
28
- <xapRights:Marked>{isCopyrightedTemplate}</xapRights:Marked>` . slice ( 1 )
29
-
30
- const XAP_OWNER = `
31
- <xapRights:Owner>
32
- <rdf:Bag>
33
- <rdf:li>{creatorNameTemplate}</rdf:li>
34
- </rdf:Bag>
35
- </xapRights:Owner>` . slice ( 1 )
36
-
37
- const DC_WORK_TITLE_TEMPLATE = `
38
- <dc:title>
39
- <rdf:Alt>
40
- <rdf:li xml:lang='x-default'>{workTitleTemplate}</rdf:li>
41
- <rdf:li xml:lang='{langTemplate}'>{workTitleTemplate}</rdf:li>
42
- </rdf:Alt>
43
- </dc:title>` . slice ( 1 )
44
-
45
- const CC_LICENSE_URL_TEMPLATE = `
46
- <cc:license rdf:resource='{licenseUrlTemplate}'/>` . slice ( 1 )
47
-
48
- const XAP_RIGHTS_USAGE_TERMS = `
49
- <xapRights:UsageTerms>
50
- <rdf:Alt>
51
- <rdf:li xml:lang='x-default'>{ccLicenseNoticeTemplate}</rdf:li>
52
- <rdf:li xml:lang='{langTemplate}' >{ccLicenseNoticeTemplate}</rdf:li>
53
- </rdf:Alt>
54
- </xapRights:UsageTerms>` . slice ( 1 )
55
-
56
- const CC_ATTRIBUTION_NAME = `
57
- <cc:attributionName>{creatorNameTemplate}</cc:attributionName>` . slice ( 1 )
58
-
59
- const LINE_START = ' '
60
- const addIndent = ( str ) => ( str . replace ( / \n / gi, '\n' + LINE_START ) )
61
-
62
23
export const createXMP = ( { shortName, workUrl = '' , workTitle = '' , creatorName = '' , lang = 'en-US' } ) => {
63
24
const slug = licenseSlug ( shortName ) . replace ( / - / gi, '_' ) . toUpperCase ( )
64
25
65
26
const licenseUrl = LICENSES [ slug ] . URL
27
+ const licenseFullName = LICENSES [ slug ] . FULL
66
28
67
- const ccLicenseUrl = addIndent ( CC_LICENSE_URL_TEMPLATE . replace ( '{licenseUrlTemplate}' , licenseUrl ) )
68
-
69
- const ccLicenseNotice = `This work is licensed under <a href="${ licenseUrl } ">${ LICENSES [ slug ] . FULL } </a>`
29
+ const ccLicenseNotice = `This work is licensed under <a href="${ licenseUrl } ">${ licenseFullName } </a>`
70
30
. replace ( / < / gi, '<' )
71
31
. replace ( / > / gi, '>' )
72
32
. replace ( / " / gi, '"' )
73
33
74
- const xapData = {
75
- owner : '' ,
76
- webStatement : '' ,
77
- marked : '' ,
78
- rightsUsageTerms : addIndent ( XAP_RIGHTS_USAGE_TERMS
79
- . replace ( '{ccLicenseNoticeTemplate}' , ccLicenseNotice )
80
- . replace ( '{langTemplate}' , lang ) )
81
- }
82
-
83
- const copyrighted = shortName !== LICENSES . CC0 . SHORT ? 'True' : 'False'
84
- xapData . marked = addIndent ( XAP_MARKED
85
- . replace ( '{isCopyrightedTemplate}' , copyrighted ) )
34
+ const isLicensed = shortName !== LICENSES . CC0 . SHORT ? 'True' : 'False'
86
35
87
- if ( workUrl ) {
88
- xapData . webStatement = addIndent ( XAP_WEB_STATEMENT
89
- . replace ( '{workUrlTemplate}' , workUrl ) )
90
- }
91
- const dcWorkTitle = workTitle
92
- ? addIndent ( DC_WORK_TITLE_TEMPLATE
93
- . replace ( / { w o r k T i t l e T e m p l a t e } / gi, workTitle )
94
- . replace ( '{langTemplate}' , lang ) )
95
- : ''
96
- let ccAttributionName = ''
97
- if ( creatorName ) {
98
- ccAttributionName = addIndent ( CC_ATTRIBUTION_NAME
99
- . replace ( '{creatorNameTemplate}' , creatorName ) )
100
- xapData . owner = addIndent ( XAP_OWNER . replace ( '{creatorNameTemplate}' , creatorName ) )
101
- }
102
- return `
103
- <?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
36
+ return ( `<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
104
37
<x:xmpmeta xmlns:x='adobe:ns:meta/'>
105
38
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
106
39
xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'
107
- xmlns:cc='http://creativecommons.org/ns#'${ workTitle ? addIndent ( "\nxmlns:dc='http://purl.org/dc/elements/1.1/'" ) : '' } >
40
+ xmlns:cc='http://creativecommons.org/ns#'${ workTitle
41
+ ? `xmlns:dc='http://purl.org/dc/elements/1.1/'`
42
+ : '' } >
108
43
<rdf:Description rdf:about=''>
109
- ${ xapData . marked }
110
- ${ xapData . owner }
111
- ${ xapData . webStatement }
112
- ${ xapData . rightsUsageTerms }
113
- ${ ccLicenseUrl }
114
- ${ ccAttributionName }
115
- ${ dcWorkTitle }
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
+ : '' }
116
73
</rdf:Description>
117
74
</rdf:RDF>
118
75
</x:xmpmeta>
119
- <?xpacket end='r'?>` . slice ( 1 )
76
+ <?xpacket end='r'?>` )
120
77
}
0 commit comments