mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
Use Math.hypot & destructure
This commit is contained in:
parent
582ce74e93
commit
96406e79ae
2
.github/label-commenter-config.yml
vendored
2
.github/label-commenter-config.yml
vendored
@ -6,7 +6,7 @@ labels:
|
|||||||
issue:
|
issue:
|
||||||
body: |
|
body: |
|
||||||
This issue has been closed because it does not meet our Issue template.
|
This issue has been closed because it does not meet our Issue template.
|
||||||
Please read our [guidelines for contributing](https://github.com/next-theme/hexo-theme-next/blob/master/.github/CONTRIBUTING.md#how-can-i-contribute)."
|
Please read our [guidelines for contributing](https://github.com/next-theme/hexo-theme-next/blob/master/.github/CONTRIBUTING.md#how-can-i-contribute).
|
||||||
action: close
|
action: close
|
||||||
- name: Need More Info
|
- name: Need More Info
|
||||||
labeled:
|
labeled:
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { parse } = require('url');
|
||||||
|
|
||||||
hexo.extend.filter.register('after_post_render', data => {
|
hexo.extend.filter.register('after_post_render', data => {
|
||||||
const { config } = hexo;
|
const { config } = hexo;
|
||||||
const theme = hexo.theme.config;
|
const theme = hexo.theme.config;
|
||||||
@ -10,14 +12,13 @@ hexo.extend.filter.register('after_post_render', data => {
|
|||||||
data.content = data.content.replace(/(<img[^>]*) src=/img, '$1 data-src=');
|
data.content = data.content.replace(/(<img[^>]*) src=/img, '$1 data-src=');
|
||||||
}
|
}
|
||||||
if (theme.exturl) {
|
if (theme.exturl) {
|
||||||
const url = require('url');
|
const siteHost = parse(config.url).hostname || config.url;
|
||||||
const siteHost = url.parse(config.url).hostname || config.url;
|
|
||||||
data.content = data.content.replace(/<a[^>]* href="([^"]+)"[^>]*>([^<]+)<\/a>/img, (match, href, html) => {
|
data.content = data.content.replace(/<a[^>]* href="([^"]+)"[^>]*>([^<]+)<\/a>/img, (match, href, html) => {
|
||||||
// Exit if the href attribute doesn't exists.
|
// Exit if the href attribute doesn't exists.
|
||||||
if (!href) return match;
|
if (!href) return match;
|
||||||
|
|
||||||
// Exit if the url has same host with `config.url`, which means it's an internal link.
|
// Exit if the url has same host with `config.url`, which means it's an internal link.
|
||||||
const link = url.parse(href);
|
const link = parse(href);
|
||||||
if (!link.protocol || link.hostname === siteHost) return match;
|
if (!link.protocol || link.hostname === siteHost) return match;
|
||||||
|
|
||||||
return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}<i class="fa fa-external-link-alt"></i></span>`;
|
return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}<i class="fa fa-external-link-alt"></i></span>`;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const url = require('url');
|
const { parse } = require('url');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export theme config to js
|
* Export theme config to js
|
||||||
@ -11,7 +11,7 @@ hexo.extend.helper.register('next_config', function() {
|
|||||||
const { config, theme, next_version } = this;
|
const { config, theme, next_version } = this;
|
||||||
config.algolia = config.algolia || {};
|
config.algolia = config.algolia || {};
|
||||||
const exportConfig = {
|
const exportConfig = {
|
||||||
hostname : url.parse(config.url).hostname || config.url,
|
hostname : parse(config.url).hostname || config.url,
|
||||||
root : config.root,
|
root : config.root,
|
||||||
scheme : theme.scheme,
|
scheme : theme.scheme,
|
||||||
version : next_version,
|
version : next_version,
|
||||||
|
|||||||
@ -3,12 +3,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { htmlTag } = require('hexo-util');
|
const { htmlTag } = require('hexo-util');
|
||||||
const url = require('url');
|
const { parse } = require('url');
|
||||||
|
|
||||||
hexo.extend.helper.register('next_url', function(path, text, options = {}) {
|
hexo.extend.helper.register('next_url', function(path, text, options = {}) {
|
||||||
const { config } = this;
|
const { config } = this;
|
||||||
const data = url.parse(path);
|
const data = parse(path);
|
||||||
const siteHost = url.parse(config.url).hostname || config.url;
|
const siteHost = parse(config.url).hostname || config.url;
|
||||||
|
|
||||||
const theme = hexo.theme.config;
|
const theme = hexo.theme.config;
|
||||||
let exturl = '';
|
let exturl = '';
|
||||||
|
|||||||
@ -22,7 +22,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
mouseupHandler: function(event) {
|
mouseupHandler: function(event) {
|
||||||
const deltaX = event.pageX - mousePos.X;
|
const deltaX = event.pageX - mousePos.X;
|
||||||
const deltaY = event.pageY - mousePos.Y;
|
const deltaY = event.pageY - mousePos.Y;
|
||||||
const clickingBlankPart = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)) < 20 && event.target.matches('.main');
|
const clickingBlankPart = Math.hypot(deltaX, deltaY) < 20 && event.target.matches('.main');
|
||||||
// Fancybox has z-index property, but medium-zoom does not, so the sidebar will overlay the zoomed image.
|
// Fancybox has z-index property, but medium-zoom does not, so the sidebar will overlay the zoomed image.
|
||||||
if (clickingBlankPart || event.target.matches('img.medium-zoom-image')) {
|
if (clickingBlankPart || event.target.matches('img.medium-zoom-image')) {
|
||||||
this.hideSidebar();
|
this.hideSidebar();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user