hswaw/site: mirror google fonts
More privacy more better.
Change-Id: I2186a3ee47f72e4a8c3e52a45c15727da0a6a9c4
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1251
Reviewed-by: q3k <q3k@hackerspace.pl>
diff --git a/hswaw/site/deps.bzl b/hswaw/site/deps.bzl
new file mode 100644
index 0000000..8bf59d1
--- /dev/null
+++ b/hswaw/site/deps.bzl
@@ -0,0 +1,45 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file", "http_archive")
+
+def hswaw_site_deps():
+ http_archive(
+ name = "com_npmjs_leaflet",
+ build_file_content = """
+filegroup(
+ name = "distfiles",
+ srcs = [
+ "package/dist/leaflet.js",
+ "package/dist/leaflet.css",
+ "package/dist/images/layers-2x.png",
+ "package/dist/images/layers.png",
+ "package/dist/images/marker-icon-2x.png",
+ "package/dist/images/marker-icon.png",
+ "package/dist/images/marker-shadow.png",
+ ],
+ visibility = ["//visibility:public"],
+)
+""",
+ sha256 = "43aca726165904ff73a34571c263b561cec94e6b9992a4414a600f3e984d1b03",
+ urls = ["https://registry.npmjs.org/leaflet/-/leaflet-1.7.1.tgz"],
+ )
+
+ http_file(
+ name = "com_gstatic_fonts_comfortaa_400",
+ sha256 = "6525a7ef8733e24b24d926150261dbc31739485fe7a3c0dbd1153d69ef2fa741",
+ urls = ["https://fonts.gstatic.com/s/comfortaa/v34/1Pt_g8LJRfWJmhDAuUsSQamb1W0lwk4S4WjMPrQ.ttf"],
+ downloaded_file_path = "font.ttf",
+ )
+
+ http_file(
+ name = "com_gstatic_fonts_inconsolata_400",
+ sha256 = "bcf01b2591ddd7b85dbdfc77ed22da40e0fe4a37b88ab08d7af5c0987212aefa",
+ urls = ["https://fonts.gstatic.com/s/inconsolata/v21/QldgNThLqRwH-OJ1UHjlKENVzkWGVkL3GZQmAwLYxYWI2qfdm7Lpp4U8aRo.ttf"],
+ downloaded_file_path = "font.ttf",
+ )
+
+ http_file(
+ name = "com_gstatic_fonts_inconsolata_700",
+ sha256 = "2952422799d3da49bcc9178800ab2111fcc21ad39048c29c15cd39005b82be5f",
+ urls = ["https://fonts.gstatic.com/s/inconsolata/v21/QldgNThLqRwH-OJ1UHjlKENVzkWGVkL3GZQmAwLYxYWI2qfdm7Lpp2I7aRo.ttf"],
+ downloaded_file_path = "font.ttf",
+ )
+
diff --git a/hswaw/site/main.go b/hswaw/site/main.go
index c1cc1e3..a0872d8 100644
--- a/hswaw/site/main.go
+++ b/hswaw/site/main.go
@@ -82,8 +82,9 @@
// $ bazel build //hswaw/site/static:static
// $ grep -A100 'Data =' bazel-bin/hswaw/site/static/static.go
staticRoutes = map[*regexp.Regexp]string{
- regexp.MustCompile(`^static/site/(.+)$`): "hswaw/site/static/%s",
- regexp.MustCompile(`^static/leaflet/(.+)$`): "external/com_npmjs_leaflet/package/dist/%s",
+ regexp.MustCompile(`^static/site/(.+)$`): "hswaw/site/static/%s",
+ regexp.MustCompile(`^static/leaflet/(.+)$`): "external/com_npmjs_leaflet/package/dist/%s",
+ regexp.MustCompile(`^static/gfonts/([a-z]+)/([0-9]+)\.ttf$`): "external/com_gstatic_fonts_%s_%s/file/font.ttf",
}
)
@@ -96,7 +97,15 @@
if match == nil {
continue
}
- to := fmt.Sprintf(to, match[1])
+ var args []interface{}
+ for _, m := range match[1:] {
+ args = append(args, m)
+ }
+ if len(args) != strings.Count(to, "%s") {
+ http.NotFound(w, r)
+ return
+ }
+ to := fmt.Sprintf(to, args...)
data, ok := static.Data[to]
if !ok {
continue
diff --git a/hswaw/site/static/BUILD.bazel b/hswaw/site/static/BUILD.bazel
index d5ea71d..9d02c09 100644
--- a/hswaw/site/static/BUILD.bazel
+++ b/hswaw/site/static/BUILD.bazel
@@ -4,16 +4,23 @@
go_embed_data(
name = "static",
srcs = [
- "animations.js",
+ "fonts.css",
"landing.css",
+
+ "animations.js",
"led.js",
- "neon-syrenka.svg",
- "@com_npmjs_leaflet//:distfiles",
- "space.jpg",
+
"frezarka.jpg",
- "tokarka.jpg",
"kuka.jpg",
+ "neon-syrenka.svg",
"serwerownia.jpg",
+ "space.jpg",
+ "tokarka.jpg",
+
+ "@com_gstatic_fonts_comfortaa_400//file:font.ttf",
+ "@com_gstatic_fonts_inconsolata_400//file:font.ttf",
+ "@com_gstatic_fonts_inconsolata_700//file:font.ttf",
+ "@com_npmjs_leaflet//:distfiles",
],
package = "static",
)
diff --git a/hswaw/site/static/fonts.css b/hswaw/site/static/fonts.css
new file mode 100644
index 0000000..fdbc7f5
--- /dev/null
+++ b/hswaw/site/static/fonts.css
@@ -0,0 +1,24 @@
+@font-face {
+ font-family: 'Comfortaa';
+ font-style: normal;
+ font-weight: 400;
+ font-display: swap;
+ src: url(/static/gfonts/comfortaa/400.ttf) format('truetype');
+}
+@font-face {
+ font-family: 'Inconsolata';
+ font-style: normal;
+ font-weight: 400;
+ font-stretch: normal;
+ font-display: swap;
+ src: url(/static/gfonts/inconsolata/400.ttf) format('truetype');
+}
+@font-face {
+ font-family: 'Inconsolata';
+ font-style: normal;
+ font-weight: 700;
+ font-stretch: normal;
+ font-display: swap;
+ src: url(/static/gfonts/inconsolata/700.ttf) format('truetype');
+}
+
diff --git a/hswaw/site/templates/index.html b/hswaw/site/templates/index.html
index 5b8bb62..e1ab0f9 100644
--- a/hswaw/site/templates/index.html
+++ b/hswaw/site/templates/index.html
@@ -4,10 +4,8 @@
<title>Warszawski Hackerspace</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/static/site/landing.css"/>
+<link rel="stylesheet" href="/static/site/fonts.css"/>
<link rel="stylesheet" href="/static/leaflet/leaflet.css"/>
-<link rel="preconnect" href="https://fonts.googleapis.com">
-<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
-<link href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@400;700&family=Comfortaa&display=swap" rel="stylesheet">
<style>
</style>
<div id="ledsFloater">