Skip to content

Commit be3a85b

Browse files
authored
Vendor jQuery and Lunr.js locally for CSP compliance (#169)
Apache's Content Security Policy on parquet.apache.org blocks scripts from external CDNs. Docsy loads jQuery from code.jquery.com and Lunr from unpkg.com, both of which get blocked, breaking all JS on the production site. This vendors both libraries in static/js/ and overrides Docsy's head.html to load them from the site itself. Same versions, just self-hosted. jQuery is still needed — Docsy's base.js and offline-search.js both depend on it (see google/docsy#1436 for their effort to drop it). Part of #163
1 parent 2cf30d7 commit be3a85b

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

layouts/partials/head.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{{/*
2+
Project-level override of Docsy's layouts/_partials/head.html
3+
4+
Why this file exists:
5+
Apache's Content Security Policy (CSP) blocks resources from external CDNs.
6+
The upstream Docsy theme loads jQuery from code.jquery.com and Lunr from
7+
unpkg.com, both of which are blocked on parquet.apache.org. This override
8+
loads vendored copies from static/js/ instead. It also removes the Algolia
9+
DocSearch CSS block since we use Lunr offline search.
10+
11+
See: https://github.com/apache/parquet-site/issues/163
12+
*/ -}}
13+
{{/* cSpell:ignore docsearch opengraph outputformat */ -}}
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
16+
{{ range .AlternativeOutputFormats -}}
17+
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
18+
{{ end -}}
19+
20+
{{ $outputFormat := partial "outputformat.html" . -}}
21+
{{ if and hugo.IsProduction (ne $outputFormat "print") -}}
22+
<meta name="robots" content="index, follow">
23+
{{ else -}}
24+
<meta name="robots" content="noindex, nofollow">
25+
{{ end -}}
26+
27+
{{ partialCached "favicons.html" . }}
28+
<title>
29+
{{- if .IsHome -}}
30+
{{ .Site.Title -}}
31+
{{ else -}}
32+
{{ with .Title }}{{ . }} | {{ end -}}
33+
{{ .Site.Title -}}
34+
{{ end -}}
35+
</title>
36+
<meta name="description" content="{{ partial "page-description.html" . }}">
37+
{{ partial "opengraph.html" . -}}
38+
{{ partial "schema.html" . -}}
39+
{{ partial "twitter_cards.html" . -}}
40+
{{ partialCached "head-css.html" . "head-css-cache-key" -}}
41+
<script src="{{ "js/jquery-3.7.1.min.js" | relURL }}"></script>
42+
{{ if .Site.Params.offlineSearch -}}
43+
<script defer src="{{ "js/lunr-2.3.9.min.js" | relURL }}"></script>
44+
{{ end -}}
45+
46+
{{ if .Site.Params.prism_syntax_highlighting -}}
47+
<link rel="stylesheet" href="{{ "css/prism.css" | relURL }}"/>
48+
{{ end -}}
49+
50+
{{ partial "hooks/head-end.html" . -}}
51+
52+
{{/* To comply with GDPR, cookie consent scripts places in head-end must execute before Google Analytics is enabled */ -}}
53+
{{ if hugo.IsProduction -}}
54+
{{ partial "google_analytics.html" . -}}
55+
{{ end -}}

static/js/jquery-3.7.1.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)