diff --git a/_config.yml b/_config.yml index e481dfb..d934a4f 100644 --- a/_config.yml +++ b/_config.yml @@ -375,6 +375,14 @@ vendors: source: cdnjs url: jquery/3.5.1/jquery.min.js sri: "sha384-ZvpUoO/+PpLXR1lu4jmpXWu80pZlYUAfxl5NsBMWOEPSjUn/6Z/hRTt8+pR6L4N2" + fancybox: + source: cdnjs + url: fancybox/3.5.7/jquery.fancybox.min.js + sri: "sha384-Zm+UU4tdcfAm29vg+MTbfu//q5B/lInMbMCr4T8c9rQFyOv6PlfQYpB5wItcXWe7" + justifiedGallery: + source: cdnjs + url: justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js + sri: "sha384-TOxsBplaL96/QDWPIUg+ye3v89qSE3s22XNtJMmCeZEep3cVDmXy1zEfZvVv+y2m" async_js: fancybox: source: cdnjs diff --git a/layout/_partials/layout.pug b/layout/_partials/layout.pug index edef9fc..3e2924b 100644 --- a/layout/_partials/layout.pug +++ b/layout/_partials/layout.pug @@ -97,8 +97,8 @@ html(lang=page.language?page.language:config.language, style=theme.grayMode ? 'f script(data-config type="text/javascript"). var LOCAL = { ispost: !{is_post()}, - path: `#{_permapath(page.path)}`, - favicon: { + path: `#{_permapath(page.path)}`, + favicon: { show: `#{__('favicon.show')}`, hide: `#{__('favicon.hide')}` }, @@ -136,6 +136,8 @@ html(lang=page.language?page.language:config.language, style=theme.grayMode ? 'f != vendor_js('pace') != vendor_js('jquery') + != vendor_js('fancybox') + != vendor_js('justifiedGallery') if theme.polyfill.enable script(src=`https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?version=4.8.0&features=${theme.polyfill.features}` defer) diff --git a/scripts/generaters/script.ts b/scripts/generaters/script.ts index d75dfc1..678e581 100644 --- a/scripts/generaters/script.ts +++ b/scripts/generaters/script.ts @@ -20,10 +20,6 @@ hexo.extend.generator.register('script', function (locals) { darkmode: theme.darkmode, auto_dark: theme.auto_dark, auto_scroll: theme.auto_scroll, - js: { - copy_tex: getVendorLink(hexo, theme.vendors.async_js.copy_tex), - fancybox: getVendorLink(hexo, theme.vendors.async_js.fancybox) - }, css: { katex: getVendorLink(hexo, theme.vendors.css.katex), mermaid: { diff --git a/source/js/_app/page/fancybox.ts b/source/js/_app/page/fancybox.ts index d54be2b..b246a5d 100644 --- a/source/js/_app/page/fancybox.ts +++ b/source/js/_app/page/fancybox.ts @@ -7,70 +7,61 @@ export const postFancybox = (p:string) => { if (document.querySelector(p + ' .md img')) { vendorCss('fancybox') vendorCss('justifiedGallery') - vendorJs('jquery', ()=>{ - vendorJs('justifiedGallery',()=>{ - vendorJs('fancybox', () => { - const q = jQuery.noConflict() + $dom.each(p + ' p.gallery', (element) => { + const box = document.createElement('div') + box.className = 'gallery' + box.setAttribute('data-height', String(element.getAttribute('data-height') || 220)) - $dom.each(p + ' p.gallery', (element) => { - const box = document.createElement('div') - box.className = 'gallery' - box.setAttribute('data-height', String(element.getAttribute('data-height') || 220)) + box.innerHTML = element.innerHTML.replace(/
/g, '') - box.innerHTML = element.innerHTML.replace(/
/g, '') - - element.parentNode.insertBefore(box, element) - element.remove() - }) - - $dom.each(p + ' .md img:not(.emoji):not(.vemoji)', (element) => { - const $image = q(element) - const imageLink = $image.attr('data-src') || $image.attr('src') // 替换 - const $imageWrapLink = $image.wrap('').parent('a') - let info; let captionClass = 'image-info' - if (!$image.is('a img')) { - $image.data('safe-src', imageLink) - if (!$image.is('.gallery img')) { - $imageWrapLink.attr('data-fancybox', 'default').attr('rel', 'default') - } else { - captionClass = 'jg-caption' - } - } - if ((info = element.getAttribute('title'))) { - $imageWrapLink.attr('data-caption', info) - const para = document.createElement('span') - const txt = document.createTextNode(info) - para.appendChild(txt) - para.addClass(captionClass) - insertAfter(element, para) - } - }) + element.parentNode.insertBefore(box, element) + element.remove() + }) - $dom.each(p + ' div.gallery', (el, i) => { - // @ts-ignore - q(el).justifiedGallery({ - rowHeight: q(el).data('height') || 120, - rel: 'gallery-' + i - }).on('jg.complete', function () { - q(this).find('a').each((k, ele) => { - ele.setAttribute('data-fancybox', 'gallery-' + i) - }) - }) - }) + $dom.each(p + ' .md img:not(.emoji):not(.vemoji)', (element) => { + const $image = $(element) + const imageLink = $image.attr('data-src') || $image.attr('src') // 替换 + const $imageWrapLink = $image.wrap('').parent('a') + let info; let captionClass = 'image-info' + if (!$image.is('a img')) { + $image.data('safe-src', imageLink) + if (!$image.is('.gallery img')) { + $imageWrapLink.attr('data-fancybox', 'default').attr('rel', 'default') + } else { + captionClass = 'jg-caption' + } + } + if ((info = element.getAttribute('title'))) { + $imageWrapLink.attr('data-caption', info) + const para = document.createElement('span') + const txt = document.createTextNode(info) + para.appendChild(txt) + para.addClass(captionClass) + insertAfter(element, para) + } + }) - q.fancybox.defaults.hash = false - q(p + ' .fancybox').fancybox({ - loop: true, - // @ts-ignore - helpers: { - overlay: { - locked: false - } - } - }) - // @ts-ignore - }, window.jQuery) + $dom.each(p + ' div.gallery', (el, i) => { + // @ts-ignore + $(el).justifiedGallery({ + rowHeight: $(el).data('height') || 120, + rel: 'gallery-' + i + }).on('jg.complete', function () { + $(this).find('a').each((k, ele) => { + ele.setAttribute('data-fancybox', 'gallery-' + i) + }) }) }) + + $.fancybox.defaults.hash = false + $(p + ' .fancybox').fancybox({ + loop: true, + // @ts-ignore + helpers: { + overlay: { + locked: false + } + } + }) } } diff --git a/source/js/_app/pjax/refresh.ts b/source/js/_app/pjax/refresh.ts index cdb630a..b9c9ab9 100644 --- a/source/js/_app/pjax/refresh.ts +++ b/source/js/_app/pjax/refresh.ts @@ -35,7 +35,7 @@ export const pjaxReload = () => { export const siteRefresh = async (reload) => { if (__shokax_antiFakeWebsite__) { - if (window.location.origin !== CONFIG.hostname) { + if (window.location.origin !== CONFIG.hostname && window.location.origin !== "http://localhost:4000") { window.location.href = CONFIG.hostname /*! 我知道你正在试图去除这段代码,虽然我无法阻止你,但我劝你好自为之 */ alert('检测到非法仿冒网站,已自动跳转回正确首页;\nWe have detected a fake website, and you have been redirected to the correct homepage.') @@ -46,8 +46,6 @@ export const siteRefresh = async (reload) => { setLocalUrl(window.location.href) vendorCss('katex'); - // await import('katex/dist/katex.min.css') - // vendorJs('copy_tex') await import('katex/dist/contrib/copy-tex.mjs') vendorCss('mermaid') diff --git a/source/js/_app/pjax/siteInit.ts b/source/js/_app/pjax/siteInit.ts index 577f0fb..044c614 100644 --- a/source/js/_app/pjax/siteInit.ts +++ b/source/js/_app/pjax/siteInit.ts @@ -100,7 +100,7 @@ const siteInit = async () => { cloudflareInit() if (__shokax_antiFakeWebsite__) { - if (window.location.origin !== CONFIG.hostname) { + if (window.location.origin !== CONFIG.hostname && window.location.origin !== "http://localhost:4000") { window.location.href = CONFIG.hostname /*! 我知道你正在试图去除这段代码,虽然我无法阻止你,但我劝你好自为之 */ alert('检测到非法仿冒网站,已自动跳转回正确首页;\nWe have detected a fake website, and you have been redirected to the correct homepage.')