Skip to content

Fix generated license html code metadata #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix html code generation
  • Loading branch information
obulat committed Jul 30, 2020
commit c7cdadf9c88378c39aacfed3aa4b045fd19db365
2 changes: 1 addition & 1 deletion src/components/LicenseCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<template v-slot:licensed-text>
<span>{{ $t('license-use.richtext.licensed-text') }}</span>
</template>
<template v-slot:licenseName>
<template v-slot:license>
<a
v-if="isWeb"
:href="licenseUrl('web')"
Expand Down
7 changes: 4 additions & 3 deletions src/components/LicenseCopy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ export default {
const licenseCodeSpan = this.$i18n.t('license-use.richtext.full-text', {
workTitle: data.workTitle ? data.workTitle : this.$i18n.t('license-use.richtext.workTitle'),
creator: data.creator,
licenseName: this.shortName,
by: data.creator ? this.$i18n.t('license-use.richtext.by') : ''
license: data.licenseLink,
by: data.creator ? this.$i18n.t('license-use.richtext.by') : '',
'licensed-text': this.$i18n.t('license-use.richtext.licensed-text')
})
return `${data.htmlString}${licenseCodeSpan}${data.licenseIconsLink}</p>`
return `${data.htmlString}${licenseCodeSpan}</p>`
},
activeTab: {
get() { return this.currentTab },
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"copy-label": "Copy",
"copied-label": "Copied!",
"richtext": {
"full-text": "{workTitle} {by} {creator}{licensed-text}{licenseName}",
"full-text": "{workTitle} {by} {creator}{licensed-text}{license}",
"workTitle": "This work",
"by": "by",
"licensed-text": " is licensed under ",
Expand Down
45 changes: 25 additions & 20 deletions src/utils/license-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,37 +119,42 @@ function generateHTML(attributionDetails, shortLicenseName) {
htmlString: '',
creator: '',
workTitle: '',
licenseIconsLink: ''
licenseLink: ''
}
dataForHtmlGeneration.htmlString = '<p xmlns:dct="http://purl.org/dc/terms/"' +
const { creatorName, creatorProfileUrl, workTitle, workUrl } = attributionDetails
dataForHtmlGeneration.htmlString =
'<p xmlns:dct="http://purl.org/dc/terms/"' +
' xmlns:cc="http://creativecommons.org/ns#"' +
' class="license-text">'
const iconStyle = 'style="height:22px!important;margin-left: 3px;vertical-align:text-bottom;"'
const baseAssetsPath = 'https://mirrors.creativecommons.org/presskit/icons'
const linkRef = '?ref=chooser-v1'
let licenseIcons = `<img ${iconStyle} src="${baseAssetsPath}/cc.svg/${linkRef}" />`
const iconStyle = 'style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"'
const assetPathBase = 'https://mirrors.creativecommons.org/presskit/icons'
const assetPathRef = '?ref=chooser-v1'
let licenseIcons = `<img ${iconStyle} src="${assetPathBase}/cc.svg${assetPathRef}" />`
if (shortLicenseName.includes('CC0')) {
shortLicenseName = 'CC CC0 1.0'
}
licenseIcons += shortLicenseName.slice(3, shortLicenseName.length - 4).split('-').map(license =>
`<img ${iconStyle} src="${baseAssetsPath}/${license.toLowerCase()}.svg/${linkRef}" />`
).join('')
dataForHtmlGeneration.licenseIconsLink = `<a rel="license" href="${licenseUrl(shortToAttr(shortLicenseName))}">${licenseIcons}</a>`
licenseIcons += shortLicenseName
.slice(3, shortLicenseName.length - 4)
.split('-')
.map(attr => `<img ${iconStyle} src="${assetPathBase}/${attr.toLowerCase()}.svg${assetPathRef}" />`
).join('')
const licenseHref = licenseUrl(shortToAttr(shortLicenseName))
dataForHtmlGeneration.licenseLink =
`<a rel="license" href="${licenseHref}">${shortLicenseName}${licenseIcons}</a>`

if (attributionDetails.creatorName) {
const creatorSpan = `<span rel="cc:attributionName">${attributionDetails.creatorName}</span>`
if (attributionDetails.creatorProfileUrl) {
dataForHtmlGeneration.creator = `<a rel="cc:attributionURL" href="${attributionDetails.creatorProfileUrl}">${creatorSpan}</a>`
if (creatorName) {
if (creatorProfileUrl) {
dataForHtmlGeneration.creator =
`<a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="${creatorProfileUrl}">${creatorName}</a>`
} else {
dataForHtmlGeneration.creator = creatorSpan
dataForHtmlGeneration.creator = `<span property="cc:attributionName">${creatorName}</span>`
}
}
if (attributionDetails.workTitle) {
const workTitleSpan = `<span rel="dct:title">${attributionDetails.workTitle}</span>`
if (attributionDetails.workUrl) {
dataForHtmlGeneration.workTitle = `<a rel="cc:attributionURL" href="${attributionDetails.workUrl}">${workTitleSpan}</a>`
if (workTitle) {
if (workUrl) {
dataForHtmlGeneration.workTitle = `<a rel="cc:attributionURL" property="dct:title" href="${workUrl}">${workTitle}</a>`
} else {
dataForHtmlGeneration.workTitle = workTitleSpan
dataForHtmlGeneration.workTitle = `<span rel="dct:title">${workTitle}</span>`
}
}
return dataForHtmlGeneration
Expand Down