Load Creative Commons badge via CDN (#267)

This commit is contained in:
Mimi 2021-05-18 01:25:16 +08:00 committed by GitHub
parent 4dbcfb3ea4
commit baf5e02b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 17 additions and 13 deletions

View File

@ -61,13 +61,15 @@ custom_logo: #/uploads/custom-logo.jpg
# Creative Commons 4.0 International License.
# See: https://creativecommons.org/about/cclicenses/
# Available values of license: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | zero
# You can set a language value if you prefer a translated version of CC license, e.g. deed.zh
# CC licenses are available in 39 languages, you can find the specific and correct abbreviation you need on https://creativecommons.org
creative_commons:
# Available values: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | cc-zero
license: by-nc-sa
# Available values: big | small
size: small
sidebar: false
post: false
# You can set a language value if you prefer a translated version of CC license, e.g. deed.zh
# CC licenses are available in 39 languages, you can find the specific and correct abbreviation you need on https://creativecommons.org
language:

View File

@ -170,3 +170,8 @@ canvas_ribbon:
unavailable:
- cdnjs
integrity: sha256-UkSSapoJqxvq+8bSCIrAhXO+aOMBRmkK6vxjTstemLs=
creative_commons:
name: '@creativecommons/vocabulary'
version: 2020.11.3
dir: assets/license_badges
alias: creativecommons-vocabulary

View File

@ -89,7 +89,7 @@
{%- if theme.creative_commons.license and theme.creative_commons.sidebar %}
<div class="cc-license site-overview-item animated" itemprop="license">
{%- set ccImage = '<img src="' + url_for(theme.images + '/cc-' + theme.creative_commons.license + '.svg') + '" alt="Creative Commons">' %}
{%- set ccImage = '<img src="' + theme.vendors.creative_commons.url + '" alt="Creative Commons">' %}
{{ next_url(ccURL, ccImage, {class: 'cc-opacity'}) }}
</div>
{%- endif %}

View File

@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const { url_for } = require('hexo-util');
let internal;
try {
internal = require('@next-theme/plugins');
@ -13,7 +14,7 @@ const vendorsFile = fs.readFileSync(path.join(__dirname, '../../../_vendors.yml'
const dependencies = yaml.load(vendorsFile);
module.exports = hexo => {
const { vendors } = hexo.theme.config;
const { vendors, creative_commons } = hexo.theme.config;
if (typeof internal === 'function') {
internal(hexo, dependencies);
}
@ -26,6 +27,9 @@ module.exports = hexo => {
};
continue;
}
if (key === 'creative_commons') {
value.file = `${value.dir}/${creative_commons.size}/${creative_commons.license.replace(/-/g, '_')}.svg`;
}
const { name, version, file, alias, unavailable } = value;
const links = {
local : url_for.call(hexo, `lib/${name}/${file}`),

View File

@ -21,7 +21,7 @@ hexo.extend.filter.register('template_locals', locals => {
// See https://github.com/hexojs/hexo/pull/4614
page.lang = page.lang || page.language;
// Creative Commons
locals.ccURL = 'https://creativecommons.org/' + (theme.creative_commons.license === 'zero' ? 'publicdomain/zero/1.0/' : 'licenses/' + theme.creative_commons.license + '/4.0/') + (theme.creative_commons.language || '');
locals.ccURL = 'https://creativecommons.org/' + (theme.creative_commons.license === 'cc-zero' ? 'publicdomain/zero/1.0/' : 'licenses/' + theme.creative_commons.license + '/4.0/') + (theme.creative_commons.language || '');
// PJAX
locals.pjax = theme.pjax ? ' data-pjax' : '';
// Front-matter

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 8.6 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 9.3 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.3 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.2 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.9 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.0 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.6 KiB