This is an automated email from the ASF dual-hosted git repository.

nihaljain pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new 984f1274d35 HBASE-29115 Fix website cannot load some resources because 
of CSP (#6668)
984f1274d35 is described below

commit 984f1274d3590ef9bbd9e0d59249a5b6c98d3e74
Author: Dávid Paksy <[email protected]>
AuthorDate: Fri Feb 28 20:17:48 2025 +0100

    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]>
---
 .../jenkins-scripts/generate-hbase-website.sh      |   8 ++
 pom.xml                                            | 128 +++++++++++++++++++++
 src/site/site.xml                                  |   6 +-
 3 files changed, 139 insertions(+), 3 deletions(-)

diff --git a/dev-support/jenkins-scripts/generate-hbase-website.sh 
b/dev-support/jenkins-scripts/generate-hbase-website.sh
index 5d080f515ba..6decee133c2 100644
--- a/dev-support/jenkins-scripts/generate-hbase-website.sh
+++ b/dev-support/jenkins-scripts/generate-hbase-website.sh
@@ -191,6 +191,14 @@ else
   exit $status
 fi
 
+# Workaround to replace MathJax CDN URI with local one in book.html
+# There is no way to influence from where the book.html Asciidoc includes the 
MathJax.js library.
+# https://docs.asciidoctor.org/asciidoctor/latest/stem/mathjax/
+# 
https://docs.asciidoctor.org/asciidoc/latest/attributes/document-attributes-ref/
+# https://github.com/asciidoctor/asciidoctor/issues/761
+echo "Replace MathJax URI"
+sed -i 's,https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/,js/,g' 
"${component_dir}"/target/site/book.html
+
 # Stage the site
 echo "Staging HBase site"
 mvn \
diff --git a/pom.xml b/pom.xml
index 92294357658..0bbb313c1e0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1038,6 +1038,7 @@
     <!-- Required for testing LDAP integration -->
     <apacheds.version>2.0.0.AM26</apacheds.version>
     <ldap-api.version>2.0.0</ldap-api.version>
+    
<webjars-dir>${project.build.directory}/META-INF/resources/webjars</webjars-dir>
   </properties>
   <!-- Sorted by groups of dependencies then groupId and artifactId -->
   <dependencyManagement>
@@ -2749,6 +2750,82 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>unpack</id>
+            <goals>
+              <goal>unpack</goal>
+            </goals>
+            <phase>pre-site</phase>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.webjars</groupId>
+                  <artifactId>bootstrap</artifactId>
+                  <version>2.3.2</version>
+                  <type>jar</type>
+                  <overWrite>true</overWrite>
+                  <includes>**/css/bootstrap-responsive.min.css</includes>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.webjars</groupId>
+                  <artifactId>highlightjs</artifactId>
+                  <version>8.7</version>
+                  <type>jar</type>
+                  <overWrite>true</overWrite>
+                  <includes>**/styles/github.min.css,
+                    **/highlight.min.js,</includes>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.webjars</groupId>
+                  <artifactId>font-awesome</artifactId>
+                  <version>4.7.0</version>
+                  <type>jar</type>
+                  <overWrite>true</overWrite>
+                  <includes>**/css/font-awesome.css,
+                    **/fonts/fontawesome-webfont.eot,
+                    **/fonts/fontawesome-webfont.svg,
+                    **/fonts/fontawesome-webfont.ttf,
+                    **/fonts/fontawesome-webfont.woff,
+                    **/fonts/fontawesome-webfont.woff2,</includes>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.webjars</groupId>
+                  <artifactId>MathJax</artifactId>
+                  <version>2.7.0</version>
+                  <type>jar</type>
+                  <overWrite>true</overWrite>
+                  <includes>**/MathJax.js,
+                    **/config/TeX-MML-AM_HTMLorMML.js,
+                    **/jax/output/HTML-CSS/jax.js,
+                    **/jax/output/HTML-CSS/imageFonts.js,
+                    **/jax/output/HTML-CSS/fonts/TeX/fontdata.js,
+                    **/jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/Main.js,
+                    
**/jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/BasicLatin.js,
+                    **/extensions/MathMenu.js,
+                    **/fonts/HTML-CSS/TeX/woff/MathJax_Main-Regular.woff,
+                    **/fonts/HTML-CSS/TeX/woff/MathJax_Main-Italic.woff,
+                    **/fonts/HTML-CSS/TeX/woff/MathJax_Math-Italic.woff,
+                    **/fonts/HTML-CSS/TeX/woff/MathJax_Size1-Regular.woff,
+                    **/fonts/HTML-CSS/TeX/woff/MathJax_Size3-Regular.woff,
+                    **/fonts/HTML-CSS/TeX/woff/MathJax_SansSerif-Italic.woff,
+                    **/fonts/HTML-CSS/TeX/otf/MathJax_Main-Regular.otf,
+                    **/fonts/HTML-CSS/TeX/otf/MathJax_Main-Italic.otf,
+                    **/fonts/HTML-CSS/TeX/otf/MathJax_Math-Italic.otf,
+                    **/fonts/HTML-CSS/TeX/otf/MathJax_Size1-Regular.otf,
+                    **/fonts/HTML-CSS/TeX/otf/MathJax_Size3-Regular.otf,
+                    
**/fonts/HTML-CSS/TeX/otf/MathJax_SansSerif-Italic.otf,</includes>
+                </artifactItem>
+              </artifactItems>
+              <!-- TODO paksyd: Check if this is bundled in our assembly 
tarballs! -->
+              <outputDirectory>${project.build.directory}</outputDirectory>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
       <!-- Special configuration for spotbugs just in the parent so
       the filter file location can be more general (see definition in 
pluginManagement) -->
       <plugin>
@@ -2802,6 +2879,8 @@
             <docVersion>${project.version}</docVersion>
             <imagesdir>images</imagesdir>
             <source-highlighter>coderay</source-highlighter>
+            <iconfont-remote>false</iconfont-remote>
+            <stylesdir>css</stylesdir>
           </attributes>
         </configuration>
         <dependencies>
@@ -2910,6 +2989,55 @@
               </target>
             </configuration>
           </execution>
+          <!-- Copy static CSS and JS files for the website. -->
+          <execution>
+            <id>copy-css-js-to-site</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <phase>pre-site</phase>
+            <configuration>
+              <target>
+                <copy flatten="true" 
todir="${project.build.directory}/site/css">
+                  <fileset dir="${webjars-dir}/bootstrap/2.3.2/css">
+                    <include name="bootstrap-responsive.min.css"/>
+                  </fileset>
+                  <fileset dir="${webjars-dir}/highlightjs/8.7/styles">
+                    <include name="github.min.css"/>
+                  </fileset>
+                  <fileset dir="${webjars-dir}/font-awesome/4.7.0/css">
+                    <include name="font-awesome.css"/>
+                  </fileset>
+                </copy>
+                <copy flatten="true" 
todir="${project.build.directory}/site/js">
+                  <fileset dir="${webjars-dir}/highlightjs/8.7/">
+                    <include name="highlight.min.js"/>
+                  </fileset>
+                  <fileset dir="${webjars-dir}/MathJax/2.7.0">
+                    <include name="MathJax.js"/>
+                  </fileset>
+                </copy>
+                <copy flatten="false" 
todir="${project.build.directory}/site/js">
+                  <fileset dir="${webjars-dir}/MathJax/2.7.0">
+                    <include name="config/TeX-MML-AM_HTMLorMML.js"/>
+                    <include name="jax/output/HTML-CSS/jax.js"/>
+                    <include name="jax/output/HTML-CSS/imageFonts.js"/>
+                    <include name="jax/output/HTML-CSS/fonts/TeX/fontdata.js"/>
+                    <include 
name="jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/Main.js"/>
+                    <include 
name="jax/output/HTML-CSS/fonts/TeX/SansSerif/Italic/BasicLatin.js"/>
+                    <include name="extensions/MathMenu.js"/>
+                    <include name="fonts/HTML-CSS/TeX/woff/MathJax_*.woff"/>
+                    <include name="fonts/HTML-CSS/TeX/otf/MathJax_*.otf"/>
+                  </fileset>
+                </copy>
+                <copy flatten="true" 
todir="${project.build.directory}/site/fonts">
+                  <fileset dir="${webjars-dir}/font-awesome/4.7.0/fonts">
+                    <include name="fontawesome-webfont.*"/>
+                  </fileset>
+                </copy>
+              </target>
+            </configuration>
+          </execution>
         </executions>
       </plugin>
       <plugin>
diff --git a/src/site/site.xml b/src/site/site.xml
index 8beb475282a..79a758ba73c 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -77,10 +77,10 @@
   <body>
     <head>
       <![CDATA[<meta name="viewport" content="width=device-width, 
initial-scale=1.0"></meta>
-      <link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap-responsive.min.css"/>
-      <link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/styles/github.min.css"/>
+      <link rel="stylesheet" href="css/bootstrap-responsive.min.css"/>
+      <link rel="stylesheet" href="css/github.min.css"/>
       <link rel="stylesheet" href="css/site.css"/>
-      <script 
src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js";></script>]]>
+      <script src="js/highlight.min.js"></script>]]>
     </head>
     <menu name="Apache HBase Project">
       <item name="Overview" href="index.html"/>

Reply via email to