-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lightGallery): 插件lgMediumZoom可能无法加载
- Loading branch information
Showing
4 changed files
with
59 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@ts-ignore | ||
import lightGallery from 'lightgallery/lib/index.js' | ||
import { LightGallerySettings } from 'lightgallery/lg-settings' | ||
import 'lightgallery/css/lightgallery-bundle.min.css' | ||
import { handleResult, solvePluginName } from './util' | ||
export interface LightGalleryOptions extends Omit<LightGallerySettings, 'plugins'> { | ||
plugins?: string[] | ||
}; | ||
export default async function initLightGallery() { | ||
const { plugins, ...opts } = mashiro_option.lightGallery as LightGalleryOptions | ||
|
||
lightGallery( | ||
document.querySelector('.entry-content'), | ||
{ | ||
plugins: plugins && (await Promise.allSettled( | ||
plugins.map( | ||
//moduleNameFormat: lgHash->lg-hash | ||
name => import( | ||
/* webpackChunkName: "lg-" */ | ||
'lightgallery/plugins/' + solvePluginName(name)+'.min.js') | ||
))) | ||
.map(handleResult), | ||
...opts | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { paramCase, } from 'change-case' | ||
|
||
export function solvePluginName(pluginName: string) { | ||
const fileName = paramCase(pluginName) | ||
const folderName = pluginName[2].toLowerCase() + pluginName.replace(/^lg\w/, '') | ||
return `${folderName}/${fileName}` | ||
} | ||
export const handleResult = (result: PromiseSettledResult<any>) => result.status == 'fulfilled' ? result.value.default : console.error('加载lightGallery的插件时出错啦!', result.reason) |