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"; import {ProviderFactory} from "./provider/provider";
class HaloJs { class HaloJs {
public static renderHalo = (src: string, fontCDN: string = null): string => { public static renderHalo = (src: string, cdn: string = null): string => {
// Load Font // Load Font
let fontStyle = document.getElementById("halo-render-font-face"); let fontStyle = document.getElementById("halo-render-font-face");
if (!fontStyle) { if (!fontStyle) {
@ -11,9 +11,9 @@ class HaloJs {
fontStyle.id = "halo-render-font-face" fontStyle.id = "halo-render-font-face"
fontStyle.innerHTML = `@font-face { fontStyle.innerHTML = `@font-face {
font-family: 'iconfont'; font-family: 'iconfont';
src: url('${fontCDN || "."}/fonts/iconfont.woff2?t=1703484934750') format('woff2'), src: url('${cdn || "."}/fonts/iconfont.woff2?t=1703484934750') format('woff2'),
url('${fontCDN || "."}/fonts/iconfont.woff?t=1703484934750') format('woff'), url('${cdn || "."}/fonts/iconfont.woff?t=1703484934750') format('woff'),
url('${fontCDN || "."}/fonts/iconfont.ttf?t=1703484934750') format('truetype'); url('${cdn || "."}/fonts/iconfont.ttf?t=1703484934750') format('truetype');
} }
` `
document.getElementsByTagName("head")[0].append(fontStyle) document.getElementsByTagName("head")[0].append(fontStyle)
@ -23,7 +23,9 @@ class HaloJs {
const type = line[0] const type = line[0]
line.splice(0, 1) line.splice(0, 1)
const content = line.join("\n") 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 { export declare interface Provider {
check: (type: string) => boolean check: (type: string) => boolean
process: (type:string,content: string) => string process: (type:string,content: string, options: IOptions) => string
} }
export class ProviderFactory { export class ProviderFactory {
@ -14,11 +14,13 @@ export class ProviderFactory {
this.providers = providers; 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>" let html = "<h2 class='invalid-type'>Invalid Type!</h2>"
this.providers.forEach(provider => { this.providers.forEach(provider => {
if (provider.check(type)) { if (provider.check(type)) {
html = provider.process(type, content) html = provider.process(type, content, options)
return return
} }
}) })
@ -32,3 +34,7 @@ export class ProviderFactory {
return this.manager return this.manager
} }
} }
export interface IOptions {
cdn: string;
}