Skip to content

Commit 7bdd0f4

Browse files
author
akmadian
committed
Get rich text generator working
1 parent 8ac92bd commit 7bdd0f4

File tree

3 files changed

+56
-41
lines changed

3 files changed

+56
-41
lines changed

src/components/HTMLGenerator.vue

+42-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,32 @@
77
aria-controls="contentIdForA11y1">
88
<h3 class="title is-3">Have a Website?</h3>
99
</button>
10-
<div class="notification">
1110
<div class="content">
11+
<span id="attribution" class="photo_usage-attribution" ref="photoAttribution">
12+
<a :href="workLocation"
13+
v-if="workTitle && workLocation"
14+
target="_blank"
15+
rel="noopener">"{{ workTitle }}"
16+
</a>
17+
<p v-if="!workTitle">This work</p>
18+
<p v-if="workTitle && !workLocation">{{ workTitle }}</p>
19+
<span v-if="attributeToName">
20+
by
21+
<a v-if="attributeToURL"
22+
:href="attributeToURL"
23+
target="_blank"
24+
rel="noopener">{{ attributeToName }}</a>
25+
<span v-else>{{ attributeToName }}</span>
26+
</span>
27+
is licensed under
28+
<a class="photo_license" :href="licenseURL" target="_blank" rel="noopener">
29+
{{ shortLicenseName }}
30+
</a>
31+
</span>
32+
<LicenseIcons
33+
:url="licenseURL"
34+
:iconsArr="iconsArr"
35+
/>
1236
<CopyButton id="copy-richtext-btn"
1337
el="#generated-richtext-container"
1438
title="Copy the attribution to paste into your blog or document"
@@ -101,22 +125,24 @@
101125
</div>
102126
</div>
103127
</div>
104-
</div>
105128
</b-collapse>
106129
</div>
107130
</template>
108131
<script>
109132
import CopyButton from './CopyButton'
110133
import LicenseIcons from './LicenseIcons'
134+
import LicenseIconography from '@creativecommons/vocabulary/vocabulary.common'
111135
import attributionHtml from '@/utils/attributionHtml'
112136
import licenseUrl from '@/utils/licenseUrl'
137+
import shortNameToIconsArray from '@/utils/licenseUtils'
113138
114139
export default {
115140
name: 'HTMLGenerator',
116141
props: ['shortLicenseName'],
117142
components: {
118143
CopyButton,
119-
LicenseIcons
144+
LicenseIcons,
145+
LicenseIconography
120146
},
121147
data() {
122148
return {
@@ -136,10 +162,18 @@ export default {
136162
attributeToName: this.attributeToName,
137163
attributeToURL: this.attributeToURL,
138164
},
139-
licenseUrl(this.$props.shortLicenseName),
165+
this.licenseURL,
140166
this.$props.shortLicenseName
141167
);
142168
}
169+
},
170+
computed: {
171+
licenseURL() {
172+
return licenseUrl(this.$props.shortLicenseName)
173+
},
174+
iconsArr() {
175+
return this.$props.shortLicenseName.toLowerCase().slice(3, this.$props.shortLicenseName.length - 4).split('-')
176+
}
143177
}
144178
}
145179
</script>
@@ -160,4 +194,8 @@ export default {
160194
.field {
161195
margin-bottom: 0px;
162196
}
197+
198+
#attribution p {
199+
display: inline
200+
}
163201
</style>

src/components/LicenseIcons.vue

+5-36
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<a :href="getLicenseURL(image)"
2+
<a :href="url"
33
@click.stop="() => false"
44
class="photo-license-icons"
55
target="_blank"
66
rel="noopener noreferrer">
77
<img class="photo-license-icon" src="../assets/license-icons/cc_icon.svg"><img
8-
v-for="(license, index) in onGetLicenseIcon(image.license)"
9-
v-if="license" class="photo-license-icon"
10-
:src="require(`@/assets/cc-${license.toLowerCase()}_icon.svg`)"
8+
v-for="(license, index) in iconsArr"
9+
class="photo-license-icon"
10+
:src="require(`../assets/license-icons/cc-${license.toLowerCase()}_icon.svg`)"
1111
:key="index">
1212
</a>
1313
</template>
@@ -16,38 +16,7 @@
1616
const LicenseIcons = {
1717
name: 'license-icons',
1818
components: {},
19-
props: {
20-
image: '',
21-
shouldWrapInLink: false,
22-
},
23-
methods: {
24-
onGetLicenseIcon(license) {
25-
let licenses = [];
26-
if (license) {
27-
licenses = license.split('-');
28-
}
29-
return licenses;
30-
},
31-
getLicenseURL(image) {
32-
if (!image) {
33-
return '';
34-
}
35-
const BASE_URL = 'https://creativecommons.org';
36-
let url = `${BASE_URL}/licenses/${image.license}/${image.license_version}`;
37-
let license = '';
38-
if (image.license) {
39-
license = image.license;
40-
}
41-
if (license === 'cc0') {
42-
this.image.license_version = '1.0';
43-
url = `${BASE_URL}/publicdomain/zero/1.0/`;
44-
}
45-
else if (image.license === 'pdm') {
46-
url = `${BASE_URL}/publicdomain/mark/1.0/`;
47-
}
48-
return url;
49-
},
50-
},
19+
props: [ 'url', 'iconsArr' ],
5120
};
5221
export default LicenseIcons;
5322
</script>

src/utils/convertLicenseName.js renamed to src/utils/licenseUtils.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ function fullToShort(fullLicenseName) {
1616
return base += " 4.0"
1717
}
1818

19-
export default { shortToFull, fullToShort }
19+
function shortNameToIconsArray(shortLicenseName) {
20+
return shortLicenseName
21+
/*
22+
.toLowerCase()
23+
.slice(3, shortLicenseName.length - 4)
24+
.split('-')*/
25+
}
26+
27+
export default { shortToFull, fullToShort, shortNameToIconsArray }

0 commit comments

Comments
 (0)