/* global hexo */ 'use strict'; const crypto = require('crypto'); const nextFont = require('./font'); const nextUrl = require('./next-url'); hexo.extend.helper.register('next_font', nextFont); hexo.extend.helper.register('next_url', nextUrl); hexo.extend.helper.register('next_inject', function(point) { return this.theme.injects[point] .map(item => this.partial(item.layout, item.locals, item.options)) .join(''); }); hexo.extend.helper.register('next_js', function(file, pjax = false) { const { next_version } = this; const { internal } = this.theme.vendors; const minified_file = file.endsWith('.js') && !file.endsWith('.min.js') ? file.slice(0, -3) + '.min.js' : file; const links = { local : this.url_for(`${this.theme.js}/${file}`), jsdelivr: `https://cdn.jsdelivr.net/npm/hexo-theme-next@${next_version}/source/js/${minified_file}`, unpkg : `https://unpkg.com/hexo-theme-next@${next_version}/source/js/${file}`, cdnjs : `https://cdnjs.cloudflare.com/ajax/libs/hexo-theme-next/${next_version}/${minified_file}` }; const src = links[internal] || links.local; return ``; }); hexo.extend.helper.register('next_vendors', function(name) { const { url, integrity } = this.theme.vendors[name]; const type = url.endsWith('css') ? 'css' : 'js'; if (type === 'css') { if (integrity) return ``; return ``; } if (integrity) return ``; return ``; }); hexo.extend.helper.register('next_data', function(name, ...data) { const json = data.length === 1 ? data[0] : Object.assign({}, ...data); return ``; }); hexo.extend.helper.register('next_pre', function() { const { preconnect } = this.theme; if (!preconnect) return ''; const { enable, host } = this.theme.font; const { internal, plugins } = this.theme.vendors; const links = { local : '', jsdelivr: 'https://cdn.jsdelivr.net', unpkg : 'https://unpkg.com', cdnjs : 'https://cdnjs.cloudflare.com' }; const h = enable ? host || 'https://fonts.googleapis.com' : ''; const i = links[internal]; const p = links[plugins]; const results = [...new Set([h, i, p].filter(origin => origin))].map( origin => `` ); return results.join('\n'); }); hexo.extend.helper.register('post_gallery', function(photos) { if (!photos || !photos.length) return ''; const content = photos.map(photo => `