Use Math.hypot & destructure

This commit is contained in:
Mimi 2020-07-22 19:46:26 +08:00
parent 582ce74e93
commit 96406e79ae
5 changed files with 11 additions and 10 deletions

View File

@ -6,7 +6,7 @@ labels:
issue:
body: |
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
- name: Need More Info
labeled:

View File

@ -2,6 +2,8 @@
'use strict';
const { parse } = require('url');
hexo.extend.filter.register('after_post_render', data => {
const { config } = hexo;
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=');
}
if (theme.exturl) {
const url = require('url');
const siteHost = url.parse(config.url).hostname || config.url;
const siteHost = parse(config.url).hostname || config.url;
data.content = data.content.replace(/<a[^>]* href="([^"]+)"[^>]*>([^<]+)<\/a>/img, (match, href, html) => {
// Exit if the href attribute doesn't exists.
if (!href) return match;
// 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;
return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}<i class="fa fa-external-link-alt"></i></span>`;

View File

@ -2,7 +2,7 @@
'use strict';
const url = require('url');
const { parse } = require('url');
/**
* Export theme config to js
@ -11,7 +11,7 @@ hexo.extend.helper.register('next_config', function() {
const { config, theme, next_version } = this;
config.algolia = config.algolia || {};
const exportConfig = {
hostname : url.parse(config.url).hostname || config.url,
hostname : parse(config.url).hostname || config.url,
root : config.root,
scheme : theme.scheme,
version : next_version,

View File

@ -3,12 +3,12 @@
'use strict';
const { htmlTag } = require('hexo-util');
const url = require('url');
const { parse } = require('url');
hexo.extend.helper.register('next_url', function(path, text, options = {}) {
const { config } = this;
const data = url.parse(path);
const siteHost = url.parse(config.url).hostname || config.url;
const data = parse(path);
const siteHost = parse(config.url).hostname || config.url;
const theme = hexo.theme.config;
let exturl = '';

View File

@ -22,7 +22,7 @@ document.addEventListener('DOMContentLoaded', () => {
mouseupHandler: function(event) {
const deltaX = event.pageX - mousePos.X;
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.
if (clickingBlankPart || event.target.matches('img.medium-zoom-image')) {
this.hideSidebar();