Add useGoogleFonts as a param to allow load fonts from google fonts cdn
Change-Id: Ic77562fb45360505134348a004ad85846ff1f18a
This commit is contained in:
@@ -130,6 +130,9 @@ public class IndexHtmlUtil {
|
|||||||
if (urlParameterMap.containsKey("sc")) {
|
if (urlParameterMap.containsKey("sc")) {
|
||||||
data.put("polyfillSC", "true");
|
data.put("polyfillSC", "true");
|
||||||
}
|
}
|
||||||
|
if (urlParameterMap.containsKey("gf")) {
|
||||||
|
data.put("useGoogleFonts", "true");
|
||||||
|
}
|
||||||
return data.build();
|
return data.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static com.google.gerrit.httpd.raw.IndexHtmlUtil.staticTemplateData;
|
|||||||
import com.google.template.soy.data.SanitizedContent;
|
import com.google.template.soy.data.SanitizedContent;
|
||||||
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer;
|
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class IndexHtmlUtilTest {
|
public class IndexHtmlUtilTest {
|
||||||
@@ -70,6 +71,17 @@ public class IndexHtmlUtilTest {
|
|||||||
"canonicalPath", "/gerrit", "staticResourcePath", ordain("http://my-cdn.com/foo/bar/"));
|
"canonicalPath", "/gerrit", "staticResourcePath", ordain("http://my-cdn.com/foo/bar/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void useGoogleFonts() throws Exception {
|
||||||
|
Map<String, String[]> urlParms = new HashMap<>();
|
||||||
|
urlParms.put("gf", new String[0]);
|
||||||
|
assertThat(
|
||||||
|
staticTemplateData(
|
||||||
|
"http://example.com/", null, null, urlParms, IndexHtmlUtilTest::ordain))
|
||||||
|
.containsExactly(
|
||||||
|
"canonicalPath", "", "staticResourcePath", ordain(""), "useGoogleFonts", "true");
|
||||||
|
}
|
||||||
|
|
||||||
private static SanitizedContent ordain(String s) {
|
private static SanitizedContent ordain(String s) {
|
||||||
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
|
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
|
||||||
s, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
|
s, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
{@param? polyfillCE: ?}
|
{@param? polyfillCE: ?}
|
||||||
{@param? polyfillSD: ?}
|
{@param? polyfillSD: ?}
|
||||||
{@param? polyfillSC: ?}
|
{@param? polyfillSC: ?}
|
||||||
|
{@param? useGoogleFonts: ?}
|
||||||
<!DOCTYPE html>{\n}
|
<!DOCTYPE html>{\n}
|
||||||
<html lang="en">{\n}
|
<html lang="en">{\n}
|
||||||
<meta charset="utf-8">{\n}
|
<meta charset="utf-8">{\n}
|
||||||
@@ -69,13 +70,17 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
// RobotoMono fonts are used in styles/fonts.css
|
// RobotoMono fonts are used in styles/fonts.css
|
||||||
// @see https://github.com/w3c/preload/issues/32 regarding crossorigin
|
{if $useGoogleFonts}
|
||||||
<link rel="preload" href="{$staticResourcePath}/fonts/RobotoMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
|
<link rel="preload" href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,500,700|Roboto:400,500,700&display=swap" as="style">
|
||||||
<link rel="preload" href="{$staticResourcePath}/fonts/RobotoMono-Regular.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
|
{else}
|
||||||
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
|
// @see https://github.com/w3c/preload/issues/32 regarding crossorigin
|
||||||
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Regular.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
|
<link rel="preload" href="{$staticResourcePath}/fonts/RobotoMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
|
||||||
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
|
<link rel="preload" href="{$staticResourcePath}/fonts/RobotoMono-Regular.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
|
||||||
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Medium.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
|
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
|
||||||
|
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Regular.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
|
||||||
|
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
|
||||||
|
<link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Medium.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
|
||||||
|
{/if}
|
||||||
<link rel="stylesheet" href="{$staticResourcePath}/styles/fonts.css">{\n}
|
<link rel="stylesheet" href="{$staticResourcePath}/styles/fonts.css">{\n}
|
||||||
<link rel="stylesheet" href="{$staticResourcePath}/styles/main.css">{\n}
|
<link rel="stylesheet" href="{$staticResourcePath}/styles/main.css">{\n}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user