Passing options such of cdn

This commit is contained in:
zhengyi 2023-12-28 10:09:09 +08:00
parent de3790c1bb
commit 8215ab73e5
2 changed files with 16 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import {RENDER_CLASS} from "./constant";
import {ProviderFactory} from "./provider/provider";
class HaloJs {
public static renderHalo = (src: string, fontCDN: string = null): string => {
public static renderHalo = (src: string, cdn: string = null): string => {
// Load Font
let fontStyle = document.getElementById("halo-render-font-face");
if (!fontStyle) {
@ -11,9 +11,9 @@ class HaloJs {
fontStyle.id = "halo-render-font-face"
fontStyle.innerHTML = `@font-face {
font-family: 'iconfont';
src: url('${fontCDN || "."}/fonts/iconfont.woff2?t=1703484934750') format('woff2'),
url('${fontCDN || "."}/fonts/iconfont.woff?t=1703484934750') format('woff'),
url('${fontCDN || "."}/fonts/iconfont.ttf?t=1703484934750') format('truetype');
src: url('${cdn || "."}/fonts/iconfont.woff2?t=1703484934750') format('woff2'),
url('${cdn || "."}/fonts/iconfont.woff?t=1703484934750') format('woff'),
url('${cdn || "."}/fonts/iconfont.ttf?t=1703484934750') format('truetype');
}
`
document.getElementsByTagName("head")[0].append(fontStyle)
@ -23,7 +23,9 @@ class HaloJs {
const type = line[0]
line.splice(0, 1)
const content = line.join("\n")
return ProviderFactory.getFactory().process(type, content)
return ProviderFactory.getFactory().process(type, content, {
cdn: cdn || "."
})
}
}

View File

@ -3,7 +3,7 @@ import {ProviderList} from "./provider-list";
export declare interface Provider {
check: (type: string) => boolean
process: (type:string,content: string) => string
process: (type:string,content: string, options: IOptions) => string
}
export class ProviderFactory {
@ -14,11 +14,13 @@ export class ProviderFactory {
this.providers = providers;
}
process(type: string, content: string) {
process(type: string, content: string, options: IOptions = {
cdn: "."
}) {
let html = "<h2 class='invalid-type'>Invalid Type!</h2>"
this.providers.forEach(provider => {
if (provider.check(type)) {
html = provider.process(type, content)
html = provider.process(type, content, options)
return
}
})
@ -32,3 +34,7 @@ export class ProviderFactory {
return this.manager
}
}
export interface IOptions {
cdn: string;
}