Skip to content

Commit cff8dbc

Browse files
committed
Add xmp download
1 parent 9248538 commit cff8dbc

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

src/App.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
6868
import HelpSection from './components/HelpSection'
6969
import Stepper from './components/Stepper'
70-
import LicenseUseCard from './components/LicenseUseCard'
7170
import HeaderSection from './components/HeaderSection'
7271
import FooterSection from './components/FooterSection'
7372
import LicenseDetailsCard from './components/LicenseDetailsCard'
@@ -78,7 +77,7 @@ export default {
7877
HelpSection,
7978
Stepper,
8079
LicenseDetailsCard,
81-
LicenseUseCard,
80+
LicenseUseCard: () => import('@/components/LicenseUseCard'),
8281
HeaderSection,
8382
FooterSection
8483
},

src/components/CopyTools.vue

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
>
1313
{{ copyLabel }}
1414
</v-button>
15-
<v-button
16-
v-else
17-
class="donate small copy-button is-xmp"
18-
>
19-
{{ xmpLabel }}
20-
</v-button>
15+
<xmp-button v-if="clipboardTarget==='.xmp'" />
2116
</div>
2217
</template>
2318

2419
<script>
2520
import CopyTypeSwitch from '@/components/CopyTypeSwitch'
2621
import Clipboard from 'clipboard'
22+
import XmpButton from '@/components/XmpButton'
23+
2724
export default {
2825
name: 'CopyTools',
29-
components: { CopyTypeSwitch },
26+
components: { CopyTypeSwitch, XmpButton },
3027
props: {
3128
clipboardTarget: {
3229
type: String,

src/components/XmpButton.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<a
3+
ref="xmp"
4+
class="button donate small copy-button is-xmp"
5+
type="text/xml"
6+
:href="xmpHref"
7+
:download="xmpFilename"
8+
>
9+
{{ xmpLabel }}
10+
</a>
11+
</template>
12+
13+
<script>
14+
import { createXMP } from '@/utils/xmp'
15+
import { mapGetters } from 'vuex'
16+
17+
export default {
18+
name: 'XmpButton',
19+
computed: {
20+
...mapGetters(['shortName']),
21+
xmpLabel() { return this.$t('license-use.xmp-label') },
22+
xmpFilename() {
23+
return `${this.shortName}.xmp`
24+
},
25+
xmpHref() {
26+
const shortName = this.$store.getters.shortName
27+
const { workUrl, workTitle, creatorName } = this.$store.state.attributionDetails
28+
const xmp = createXMP({ shortName, workUrl, workTitle, creatorName })
29+
const xmpBlob = new Blob([xmp], { type: 'text/xml;charset=utf-8' })
30+
return URL.createObjectURL(xmpBlob)
31+
}
32+
}
33+
}
34+
</script>

src/utils/xmp.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)