@paperbits/common
Advanced tools
Comparing version 0.1.576 to 0.1.577
@@ -19,2 +19,3 @@ import { Loader, LoaderOptions } from "@googlemaps/js-api-loader"; | ||
this.initPromise = this.loadGoogleApi(); | ||
return this.initPromise; | ||
} | ||
@@ -21,0 +22,0 @@ |
@@ -133,3 +133,4 @@ import * as Arrays from "./arrays"; | ||
Language = "lang", | ||
Direction = "dir" | ||
Direction = "dir", | ||
Charset = "charset" | ||
} | ||
@@ -136,0 +137,0 @@ |
{ | ||
"name": "@paperbits/common", | ||
"version": "0.1.576", | ||
"version": "0.1.577", | ||
"description": "Paperbits common components.", | ||
@@ -5,0 +5,0 @@ "author": "Paperbits", |
@@ -0,3 +1,5 @@ | ||
import * as Utils from "@paperbits/common"; | ||
import { MimeTypes } from "@paperbits/common"; | ||
import { Attributes } from "@paperbits/common/html"; | ||
import { ISettingsProvider } from "../configuration"; | ||
import { HtmlDocumentProvider } from "./htmlDocumentProvider"; | ||
@@ -11,11 +13,20 @@ import { HtmlPage } from "./htmlPage"; | ||
export class HtmlPagePublisher { | ||
private subresourceIntegrityEnabled: boolean; | ||
constructor( | ||
private readonly htmlDocumentProvider: HtmlDocumentProvider, | ||
private readonly htmlPagePublisherPlugins: HtmlPagePublisherPlugin[], | ||
private readonly htmlPageOptimizer: HtmlPageOptimizer | ||
private readonly htmlPageOptimizer: HtmlPageOptimizer, | ||
private readonly settingsProvider: ISettingsProvider | ||
) { } | ||
private initialize = Utils.debounce(this.loadSettings.bind(this)); | ||
private async loadSettings(): Promise<void> { | ||
this.subresourceIntegrityEnabled = !!await this.settingsProvider.getSetting<boolean>("features/subresourceIntegrity"); | ||
} | ||
private scaffoldPageDocument(document: Document): void { | ||
const charsetMetaElement: HTMLMetaElement = document.createElement("meta"); | ||
charsetMetaElement.setAttribute("charset", "utf-8"); | ||
charsetMetaElement.setAttribute(Attributes.Charset, "utf-8"); | ||
document.head.appendChild(charsetMetaElement); | ||
@@ -40,3 +51,3 @@ | ||
if (stylesheetLink.integrity) { | ||
if (this.subresourceIntegrityEnabled && stylesheetLink.integrity) { | ||
element.setAttribute(Attributes.Integrity, stylesheetLink.integrity); | ||
@@ -55,3 +66,3 @@ } | ||
if (scriptLink.integrity) { | ||
if (this.subresourceIntegrityEnabled && scriptLink.integrity) { | ||
element.setAttribute(Attributes.Integrity, scriptLink.integrity); | ||
@@ -74,2 +85,4 @@ } | ||
try { | ||
await this.initialize(); | ||
const document = this.htmlDocumentProvider.createDocument(); | ||
@@ -76,0 +89,0 @@ this.scaffoldPageDocument(document); |
@@ -394,2 +394,7 @@ import * as h2p from "html2plaintext"; | ||
return value.length > length ? `${value.substring(0, length)}...` : value; | ||
} | ||
export function debounce(func: () => Promise<void>): () => Promise<void> { | ||
let promise: Promise<void>; | ||
return () => promise ? promise : promise = func(); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
437788
10987