Skip to content

Commit

Permalink
fix: #342
Browse files Browse the repository at this point in the history
  • Loading branch information
zkz098 committed Jan 27, 2025
1 parent 1e1e4bb commit 298d0c7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 69 deletions.
8 changes: 8 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions layout/_partials/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`
},
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions scripts/generaters/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
109 changes: 50 additions & 59 deletions source/js/_app/page/fancybox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<br>/g, '')

box.innerHTML = element.innerHTML.replace(/<br>/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('<a class="fancybox" href="' + imageLink + '" itemscope itemtype="https://schema.org/ImageObject" itemprop="url"></a>').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('<a class="fancybox" href="' + imageLink + '" itemscope itemtype="https://schema.org/ImageObject" itemprop="url"></a>').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
}
}
})
}
}
4 changes: 1 addition & 3 deletions source/js/_app/pjax/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion source/js/_app/pjax/siteInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down

0 comments on commit 298d0c7

Please sign in to comment.