1// Copyright (C) 2018 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14ext.fixJavadoc = { 15 def javadocPath = "${project.buildDir}/docs/javadoc" 16 // Fix external Android links to target the top frame. 17 def androidRoot = "https://developer.android.com/reference/" 18 def androidLink = "<a href=\"(${androidRoot}.*?)\\?is-external=true(.*)\"" 19 def androidFixed = "<a href=\"\\1\\2\" target=\"_top\"" 20 ant.replaceregexp(match:androidLink, replace:androidFixed, flags:'g') { 21 fileset(dir: "${javadocPath}", includes: "**/*.html") 22 } 23 // Add favicon to each page 24 def headTag = "<head>" 25 def headTagWithFavicon = "<head>" + 26 "<!-- start favicons snippet, use https://realfavicongenerator.net/ -->" + 27 "<link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"/assets/apple-touch-icon.png\">" + 28 "<link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/assets/favicon-32x32.png\">" + 29 "<link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/assets/favicon-16x16.png\">" + 30 "<link rel=\"manifest\" href=\"/assets/site.webmanifest\">" + 31 "<link rel=\"mask-icon\" href=\"/assets/safari-pinned-tab.svg\" color=\"#fc4d50\">" + 32 "<link rel=\"shortcut icon\" href=\"/assets/favicon.ico\">" + 33 "<meta name=\"msapplication-TileColor\" content=\"#ffc40d\">" + 34 "<meta name=\"msapplication-config\" content=\"/assets/browserconfig.xml\">" + 35 "<meta name=\"theme-color\" content=\"#ffffff\">" + 36 "<!-- end favicons snippet -->" 37 ant.replaceregexp(match:headTag, replace:headTagWithFavicon, flags:'g') { 38 fileset(dir: "${javadocPath}", includes: "**/*.html") 39 } 40 // Remove date metadata that changes every time Javadoc is generated. 41 def javadocGeneratedBy = "<!-- Generated by javadoc.*?-->\n" 42 ant.replaceregexp(match:javadocGeneratedBy, replace:"") { 43 fileset(dir: "${javadocPath}", includes: "**/*.html") 44 } 45 def dateMeta = "<meta name=\"date\".*?>\n" 46 ant.replaceregexp(match:dateMeta, replace:"") { 47 fileset(dir: "${javadocPath}", includes: "**/*.html") 48 } 49} 50