@@ -103,4 +103,47 @@ function licenseIconsArr(licenseAttributes) {
103103 return iconsArray
104104}
105105
106- export { defaultAttributes , CC0Attributes , CCBYAttributes , visibleSetters , disabledSetters , shortToAttr , attrToShort , attrToFull , licenseUrl , licenseSlug , licenseIconsArr }
106+ function generateHTML ( attributionDetails , shortLicenseName ) {
107+ const dataForHtmlGeneration = {
108+ htmlString : '' ,
109+ creator : '' ,
110+ workTitle : '' ,
111+ licenseIconsLink : ''
112+ }
113+ dataForHtmlGeneration . htmlString = '<p xmlns:dct="http://purl.org/dc/terms/"' +
114+ ' xmlns:cc="http://creativecommons.org/ns#"' +
115+ ' class="license-text">'
116+ const iconStyle = 'style="height:22px!important;margin-left: 3px;vertical-align:text-bottom;"'
117+ const baseAssetsPath = 'https://search.creativecommons.org/static/img'
118+ let licenseIcons = `<img ${ iconStyle } src="${ baseAssetsPath } /cc_icon.svg" />`
119+ if ( shortLicenseName . includes ( 'CC0' ) ) {
120+ shortLicenseName = 'CC CC0 1.0'
121+ }
122+ licenseIcons += shortLicenseName . slice ( 3 , shortLicenseName . length - 4 ) . split ( '-' ) . map ( license =>
123+ `<img ${ iconStyle } src="${ baseAssetsPath } /cc-${ license . toLowerCase ( ) } _icon.svg" />`
124+ ) . join ( '' )
125+ dataForHtmlGeneration . licenseIconsLink = `<a href="${ licenseUrl ( shortToAttr ( shortLicenseName ) ) } ">${ licenseIcons } </a>`
126+
127+ if ( attributionDetails . creatorName ) {
128+ const creatorSpan = `<span rel="cc:attributionName">${ attributionDetails . creatorName } </span>`
129+ if ( attributionDetails . creatorProfileUrl ) {
130+ dataForHtmlGeneration . creator = `<a rel="cc:attributionURL" href="${ attributionDetails . creatorProfileUrl } ">${ creatorSpan } </a>`
131+ } else {
132+ dataForHtmlGeneration . creator = creatorSpan
133+ }
134+ }
135+ if ( attributionDetails . workTitle ) {
136+ const workTitleSpan = `<span rel="dc:title">${ attributionDetails . workTitle } </span>`
137+ if ( attributionDetails . workUrl ) {
138+ dataForHtmlGeneration . workTitle = `<a rel="cc:attributionURL" href="${ attributionDetails . workUrl } ">${ workTitleSpan } </a>`
139+ } else {
140+ dataForHtmlGeneration . workTitle = workTitleSpan
141+ }
142+ }
143+ return dataForHtmlGeneration
144+ }
145+ export {
146+ defaultAttributes , CC0Attributes , CCBYAttributes , visibleSetters , disabledSetters ,
147+ shortToAttr , attrToShort , attrToFull , licenseUrl , licenseSlug , licenseIconsArr ,
148+ generateHTML
149+ }
0 commit comments