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>
This commit is contained in:
q3k 2022-02-01 09:36:47 +00:00 committed by q3k
parent f92437451c
commit 19c8b60a42
6 changed files with 97 additions and 32 deletions

View file

@ -285,27 +285,9 @@ http_archive(
urls = ["https://github.com/stedolan/jq/releases/download/jq-1.6/jq-1.6.tar.gz"],
)
# leaflet.js from NPM, used by //hswaw/site.
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"],
)
# //hswaw/site deps.
load("//hswaw/site:deps.bzl", "hswaw_site_deps")
hswaw_site_deps()
# noVNC, used by //dc/drackvm.
http_archive(

45
hswaw/site/deps.bzl Normal file
View file

@ -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",
)

View file

@ -82,8 +82,9 @@ var (
// $ 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 @@ func (s *service) handleHTTPStatic(w http.ResponseWriter, r *http.Request) {
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

View file

@ -4,16 +4,23 @@ load("@io_bazel_rules_go//extras:embed_data.bzl", "go_embed_data")
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",
)

View file

@ -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');
}

View file

@ -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">