Skip to content

Commit 62ba5cf

Browse files
committed
Refactor license code generation
License Icons in rich text are again generated from local svg files to minimize loading data and flickering of the icons. Links for html icons are different in order to ensure that the links are permanent. License code generation is done inside the SelectedLicenseCode component. Signed-off-by: Olga Bulat <obulat@gmail.com>
1 parent ccb513d commit 62ba5cf

File tree

3 files changed

+72
-87
lines changed

3 files changed

+72
-87
lines changed

src/components/LicenseIcons.vue

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
<template>
2-
<a :href="url"
3-
@click.stop="() => false"
4-
class="photo-license-icons"
5-
target="_blank"
6-
rel="noopener noreferrer">
7-
<img class="photo-license-icon" src="../assets/license-icons/cc_icon.svg"><img
8-
v-for="(license, index) in iconsArr"
9-
class="photo-license-icon"
10-
:src="require(`../assets/license-icons/cc-${license.toLowerCase()}_icon.svg`)"
11-
:key="index">
12-
</a>
2+
<a :href="url"
3+
@click.stop="() => false"
4+
class="photo-license-icons"
5+
target="_blank"
6+
rel="noopener noreferrer">
7+
<img class="photo-license-icon"
8+
src="../assets/license-icons/cc_icon.svg">
9+
<img v-for="(license, index) in iconsArr"
10+
class="photo-license-icon"
11+
:src="require(`../assets/license-icons/cc-${license.toLowerCase()}_icon.svg`)"
12+
:key="index">
13+
</a>
1314
</template>
1415

1516
<script>
16-
/* eslint-disable */
1717
const LicenseIcons = {
18-
name: 'license-icons',
19-
components: {},
20-
props: [ 'url', 'iconsArr' ],
21-
};
22-
export default LicenseIcons;
18+
name: 'license-icons',
19+
components: {},
20+
props: ['url', 'iconsArr']
21+
}
22+
export default LicenseIcons
2323
</script>
2424
<style lang="scss" scoped>
25-
.photo-license-icons {
26-
display: inline-block;
27-
white-space: none;
28-
opacity: .7;
29-
margin-top: 2px;
30-
height: 22px !important;
25+
.photo-license-icons {
26+
display: inline-block;
27+
white-space: nowrap;
28+
vertical-align: text-bottom;
29+
opacity: .7;
30+
margin-right:3px;
31+
height: 22px !important;
3132
&:hover {
32-
opacity: 1;
33+
opacity: 1;
3334
}
3435
}
3536
.photo-license-icon {
36-
height: inherit;
37-
margin-right: 3px;
37+
height: inherit;
38+
margin-left: 3px;
3839
}
3940
</style>

src/components/SelectedLicenseCode.vue

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99
v-model="activeTab"
1010
>
1111
<b-tab-item :label="this.$t('use-license.rich-text-label')">
12-
<div id="attribution-richtext"
13-
v-html="this.htmlElement"/>
12+
<div id="attribution-richtext">
13+
<p xmlns:dct="http://purl.org/dc/terms/" xmlns:cc="http://creativecommons.org/ns#">
14+
<span v-html="this.licenseCodeTextSpan" />
15+
<LicenseIcons
16+
:url="this.$licenseUrl(this.$props.value.shortName)"
17+
:iconsArr="this.$licenseIconsArr(this.$props.value.shortName)"/>
18+
</p>
19+
</div>
1420
</b-tab-item>
1521
<b-tab-item :label="this.$t('use-license.html-label')">
1622
<div class='control' id='generated-html-container'>
1723
<textarea id='attribution-html'
1824
class='textarea'
19-
:value="htmlElement"
25+
:value="htmlLicenseParagraph"
2026
readonly
2127
/>
2228
</div>
@@ -52,10 +58,13 @@
5258
</template>
5359
<script>
5460
import Clipboard from 'clipboard'
55-
import { workAuthor, workLicense } from '@/utils/attributionHtml'
61+
import LicenseIcons from './LicenseIcons'
5662
5763
export default {
5864
name: 'SelectedLicenseCode',
65+
components: {
66+
LicenseIcons
67+
},
5968
props: ['value'],
6069
data() {
6170
return {
@@ -87,15 +96,20 @@ export default {
8796
licenseURL() {
8897
return this.$licenseUrl(this.$props.value.shortName)
8998
},
90-
workLicenseElement() {
91-
return workLicense(this.licenseURL,
92-
this.$props.value.shortName)
99+
licenseLink() {
100+
const short = this.$props.value.shortName.toUpperCase()
101+
const attrs = 'target="_blank" rel="license noopener noreferrer" style="display: inline-block;">'
102+
return `<a href="${this.licenseURL}" ${attrs}${short}</a>`
93103
},
94104
authorElement() {
95-
return workAuthor({
96-
creatorName: this.$props.value.attributionDetails.creatorName,
97-
creatorProfileUrl: this.$props.value.attributionDetails.creatorProfileUrl
98-
})
105+
const name = this.$props.value.attributionDetails.creatorName
106+
const profile = this.$props.value.attributionDetails.creatorProfileUrl
107+
if (name) {
108+
const creatorNameNoLink = `<span rel="cc:attributionName">${name}</span>`
109+
return profile
110+
? `by <a rel="cc:attributionURL" href="${profile}">${creatorNameNoLink}</a>`
111+
: `by ${creatorNameNoLink}`
112+
} else return ''
99113
},
100114
titleElement() {
101115
const workUrl = this.$props.value.attributionDetails.workUrl
@@ -112,14 +126,27 @@ export default {
112126
}
113127
}
114128
},
115-
htmlElement() {
116-
const licenseText = this.$t('code-text.license-text', {
129+
licenseCodeTextSpan() {
130+
const attributionCode = this.$t('code-text.license-text', {
117131
workTitle: this.titleElement,
118132
byLine: this.authorElement
119133
})
120-
const paragraphBeginning = '<p id="license-code" xmlns:dct="http://purl.org/dc/terms/" xmlns:cc="http://creativecommons.org/ns#">'
121-
const fullLicenseCode = `${paragraphBeginning}${licenseText}${this.workLicenseElement}</p>`
122-
return fullLicenseCode
134+
return `${attributionCode}${this.licenseLink}`
135+
},
136+
htmlLicenseParagraph() {
137+
let short = this.$props.value.shortName
138+
const iconStyle = 'style="height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7;"'
139+
const baseAssetsPath = 'https://search.creativecommons.org/static/img'
140+
let licenseIcons = `<img ${iconStyle} src="${baseAssetsPath}/cc_icon.svg" />`
141+
if (short.includes('CC0')) {
142+
short = 'CC CC0 1.0'
143+
}
144+
licenseIcons += short.slice(3, short.length - 4).split('-').map(license =>
145+
`<img ${iconStyle} src="${baseAssetsPath}/cc-${license.toLowerCase()}_icon.svg" />`
146+
).join('')
147+
const licenseIconsLink = `<a href="${this.licenseURL}">${licenseIcons}</a>`
148+
const ccrelcode = 'xmlns:dct="http://purl.org/dc/terms/" xmlns:cc="http://creativecommons.org/ns#"'
149+
return `<p ${ccrelcode}>${this.licenseCodeTextSpan}${licenseIconsLink}</p>`
123150
},
124151
activeTab: {
125152
get() { return this.currentTab },
@@ -130,7 +157,7 @@ export default {
130157
this.currentSelection = this.currentTab === 0 ? 'richtext' : 'html'
131158
const tab = this.currentTab
132159
this.currentTab = 2
133-
this.copyText = this.$t('copied-label')
160+
this.copyText = this.$t('use-license.copied-label')
134161
setTimeout(() => {
135162
this.currentTab = tab
136163
}, 1)
@@ -165,7 +192,7 @@ export default {
165192
.use-license-hint span {
166193
vertical-align: middle;
167194
}
168-
div.license-code {
195+
.license-code {
169196
margin-top: 0.4rem;
170197
h2.vocab-h2{
171198
font-family: Roboto Condensed;

src/utils/attributionHtml.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)