Skip to content

Commit 984f127

Browse files
authored
HBASE-29115 Fix website cannot load some resources because of CSP (#6668)
* Self-host Bootstrap CSS, highlight.js (CSS and JS) for the website instead of trying load it from CDN-s. Because of the new CSP, loading these from CDN-s is blocked. * Switch to local fontawesome (used for icons) in Reference Guide (book.html) instead of using CDN as per this guide: https://docs.asciidoctor.org/asciidoctor/latest/html-backend/local-font-awesome/ * Set stylesdir so that book.html will include /css/font-awesome.css (where the file is) and not /font-awesome.css * Replace MathJax CDN URI with local one in book.html Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Nihal Jain <[email protected]>
1 parent fd50561 commit 984f127

3 files changed

Lines changed: 139 additions & 3 deletions

File tree

dev-support/jenkins-scripts/generate-hbase-website.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ else
191191
exit $status
192192
fi
193193

194+
# Workaround to replace MathJax CDN URI with local one in book.html
195+
# There is no way to influence from where the book.html Asciidoc includes the MathJax.js library.
196+
# https://docs.asciidoctor.org/asciidoctor/latest/stem/mathjax/
197+
# https://docs.asciidoctor.org/asciidoc/latest/attributes/document-attributes-ref/
198+
# https://github.com/asciidoctor/asciidoctor/issues/761
199+
echo "Replace MathJax URI"
200+
sed -i 's,https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/,js/,g' "${component_dir}"/target/site/book.html
201+
194202
# Stage the site
195203
echo "Staging HBase site"
196204
mvn \

pom.xml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@
10381038
<!-- Required for testing LDAP integration -->
10391039
<apacheds.version>2.0.0.AM26</apacheds.version>
10401040
<ldap-api.version>2.0.0</ldap-api.version>
1041+
<webjars-dir>${project.build.directory}/META-INF/resources/webjars</webjars-dir>
10411042
</properties>
10421043
<!-- Sorted by groups of dependencies then groupId and artifactId -->
10431044
<dependencyManagement>
@@ -2749,6 +2750,82 @@
27492750
</execution>
27502751
</executions>
27512752
</plugin>
2753+
<plugin>
2754+
<groupId>org.apache.maven.plugins</groupId>
2755+
<artifactId>maven-dependency-plugin</artifactId>
2756+
<executions>
2757+
<execution>
2758+
<id>unpack</id>
2759+
<goals>
2760+
<goal>unpack</goal>
2761+
</goals>
2762+
<phase>pre-site</phase>
2763+
<configuration>
2764+
<artifactItems>
2765+
<artifactItem>
2766+
<groupId>org.webjars</groupId>
2767+
<artifactId>bootstrap</artifactId>
2768+
<version>2.3.2</version>
2769+
<type>jar</type>
2770+
<overWrite>true</overWrite>
2771+
<includes>**/css/bootstrap-responsive.min.css</includes>
2772+
</artifactItem>
2773+
<artifactItem>
2774+
<groupId>org.webjars</groupId>
2775+
<artifactId>highlightjs</artifactId>
2776+
<version>8.7</version>
2777+
<type>jar</type>
2778+
<overWrite>true</overWrite>
2779+
<includes>**/styles/github.min.css,
2780+
**/highlight.min.js,</includes>
2781+
</artifactItem>
2782+
<artifactItem>
2783+
<groupId>org.webjars</groupId>
2784+
<artifactId>font-awesome</artifactId>
2785+
<version>4.7.0</version>
2786+
<type>jar</type>
2787+
<overWrite>true</overWrite>
2788+
<includes>**/css/font-awesome.css,
2789+
**/fonts/fontawesome-webfont.eot,
2790+
**/fonts/fontawesome-webfont.svg,
2791+
**/fonts/fontawesome-webfont.ttf,
2792+
**/fonts/fontawesome-webfont.woff,
2793+
**/fonts/fontawesome-webfont.woff2,</includes>
2794+
</artifactItem>
2795+
<artifactItem>
2796+
<groupId>org.webjars</groupId>
2797+
<artifactId>MathJax</artifactId>
2798+
<version>2.7.0</version>
2799+
<type>jar</type>
2800+
<overWrite>true</overWrite>
2801+
<includes>**/MathJax.js,
2802+
**/config/TeX-MML-AM_HTMLorMML.js,
2803+
**/jax/output/HTML-CSS/jax.js,
2804+
**/jax/output/HTML-CSS/imageFonts.js,
2805+
**/jax/output/HTML-CSS/fonts/TeX/fontdata.js,
2806+
**/jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/Main.js,
2807+
**/jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/BasicLatin.js,
2808+
**/extensions/MathMenu.js,
2809+
**/fonts/HTML-CSS/TeX/woff/MathJax_Main-Regular.woff,
2810+
**/fonts/HTML-CSS/TeX/woff/MathJax_Main-Italic.woff,
2811+
**/fonts/HTML-CSS/TeX/woff/MathJax_Math-Italic.woff,
2812+
**/fonts/HTML-CSS/TeX/woff/MathJax_Size1-Regular.woff,
2813+
**/fonts/HTML-CSS/TeX/woff/MathJax_Size3-Regular.woff,
2814+
**/fonts/HTML-CSS/TeX/woff/MathJax_SansSerif-Italic.woff,
2815+
**/fonts/HTML-CSS/TeX/otf/MathJax_Main-Regular.otf,
2816+
**/fonts/HTML-CSS/TeX/otf/MathJax_Main-Italic.otf,
2817+
**/fonts/HTML-CSS/TeX/otf/MathJax_Math-Italic.otf,
2818+
**/fonts/HTML-CSS/TeX/otf/MathJax_Size1-Regular.otf,
2819+
**/fonts/HTML-CSS/TeX/otf/MathJax_Size3-Regular.otf,
2820+
**/fonts/HTML-CSS/TeX/otf/MathJax_SansSerif-Italic.otf,</includes>
2821+
</artifactItem>
2822+
</artifactItems>
2823+
<!-- TODO paksyd: Check if this is bundled in our assembly tarballs! -->
2824+
<outputDirectory>${project.build.directory}</outputDirectory>
2825+
</configuration>
2826+
</execution>
2827+
</executions>
2828+
</plugin>
27522829
<!-- Special configuration for spotbugs just in the parent so
27532830
the filter file location can be more general (see definition in pluginManagement) -->
27542831
<plugin>
@@ -2802,6 +2879,8 @@
28022879
<docVersion>${project.version}</docVersion>
28032880
<imagesdir>images</imagesdir>
28042881
<source-highlighter>coderay</source-highlighter>
2882+
<iconfont-remote>false</iconfont-remote>
2883+
<stylesdir>css</stylesdir>
28052884
</attributes>
28062885
</configuration>
28072886
<dependencies>
@@ -2910,6 +2989,55 @@
29102989
</target>
29112990
</configuration>
29122991
</execution>
2992+
<!-- Copy static CSS and JS files for the website. -->
2993+
<execution>
2994+
<id>copy-css-js-to-site</id>
2995+
<goals>
2996+
<goal>run</goal>
2997+
</goals>
2998+
<phase>pre-site</phase>
2999+
<configuration>
3000+
<target>
3001+
<copy flatten="true" todir="${project.build.directory}/site/css">
3002+
<fileset dir="${webjars-dir}/bootstrap/2.3.2/css">
3003+
<include name="bootstrap-responsive.min.css"/>
3004+
</fileset>
3005+
<fileset dir="${webjars-dir}/highlightjs/8.7/styles">
3006+
<include name="github.min.css"/>
3007+
</fileset>
3008+
<fileset dir="${webjars-dir}/font-awesome/4.7.0/css">
3009+
<include name="font-awesome.css"/>
3010+
</fileset>
3011+
</copy>
3012+
<copy flatten="true" todir="${project.build.directory}/site/js">
3013+
<fileset dir="${webjars-dir}/highlightjs/8.7/">
3014+
<include name="highlight.min.js"/>
3015+
</fileset>
3016+
<fileset dir="${webjars-dir}/MathJax/2.7.0">
3017+
<include name="MathJax.js"/>
3018+
</fileset>
3019+
</copy>
3020+
<copy flatten="false" todir="${project.build.directory}/site/js">
3021+
<fileset dir="${webjars-dir}/MathJax/2.7.0">
3022+
<include name="config/TeX-MML-AM_HTMLorMML.js"/>
3023+
<include name="jax/output/HTML-CSS/jax.js"/>
3024+
<include name="jax/output/HTML-CSS/imageFonts.js"/>
3025+
<include name="jax/output/HTML-CSS/fonts/TeX/fontdata.js"/>
3026+
<include name="jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/Main.js"/>
3027+
<include name="jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/BasicLatin.js"/>
3028+
<include name="extensions/MathMenu.js"/>
3029+
<include name="fonts/HTML-CSS/TeX/woff/MathJax_*.woff"/>
3030+
<include name="fonts/HTML-CSS/TeX/otf/MathJax_*.otf"/>
3031+
</fileset>
3032+
</copy>
3033+
<copy flatten="true" todir="${project.build.directory}/site/fonts">
3034+
<fileset dir="${webjars-dir}/font-awesome/4.7.0/fonts">
3035+
<include name="fontawesome-webfont.*"/>
3036+
</fileset>
3037+
</copy>
3038+
</target>
3039+
</configuration>
3040+
</execution>
29133041
</executions>
29143042
</plugin>
29153043
<plugin>

src/site/site.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
<body>
7878
<head>
7979
<![CDATA[<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
80-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap-responsive.min.css"/>
81-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/styles/github.min.css"/>
80+
<link rel="stylesheet" href="css/bootstrap-responsive.min.css"/>
81+
<link rel="stylesheet" href="css/github.min.css"/>
8282
<link rel="stylesheet" href="css/site.css"/>
83-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js"></script>]]>
83+
<script src="js/highlight.min.js"></script>]]>
8484
</head>
8585
<menu name="Apache HBase Project">
8686
<item name="Overview" href="index.html"/>

0 commit comments

Comments
 (0)