3 Star 4 Fork 1

Gitee 极速下载/LiquiBASE

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/liquibase/liquibase.github.com
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
listRedirects.groovy 4.39 KB
一键复制 编辑 原始数据 按行查看 历史
Steve Donie 提交于 2020-01-16 12:13 . add more info about 'type 4'
#! /usr/bin/env groovy
// list any redirects, showing the actual url and the redirect url
// There are three ways to do redirects that I have found:
//
// Method 1 - in markdown files:for an example, see liquibase.github.com/download/index.md, which contains:
// ---
// title: Download Liquibase
// redirect_to:
//   - http://download.liquibase.org
// ---
// Method 2 - in xml?
// I also see liquibase.github.com/feed (as a plain text file, no extension) that contains:
// <?xml version="1.0"?>
// <redirect>
// <newLocation>
//     http://www.liquibase.org/rss.xml
// </newLocation>
// </redirect>
//
// Method 3 - in HTML:example - see liquibase.github.com/extensions/index.html
// <html>
// <head>
//     <meta http-equiv="refresh" content="0;url=https://liquibase.jira.com/wiki/display/CONTRIB/LiquiBase+Extensions+Portal">
// </head>
// </html>
//
// This script will show all of these types.
//
@Grapes(
@Grab(group='commons-io', module='commons-io', version='2.6')
)
import org.apache.commons.io.FilenameUtils
// map of page name to count of links to that page
def allPages = [:]
// map of extension to count of number of files with that extension
def extensions = [:]
// a wrapper closure around executing a string
// can take either a string or a list of strings (for arguments with spaces)
// returns a count of lines in the output.
def getCountFromCommand = { strList, dirName ->
def proc = strList.execute(null,new File(dirName))
def stdout = new StringBuilder(), stderr = new StringBuilder()
proc.consumeProcessOutput(stdout, stderr)
proc.waitForOrKill(1000)
def output = stdout.toString()
int count = 0
if (output.length() > 0) {
count = output.split("\r\n|\r|\n").length;
}
return count
}
// a wrapper closure around executing a string
// can take either a string or a list of strings (for arguments with spaces)
// prints the output
def runCommand = { strList, dirName ->
def proc = strList.execute(null,new File(dirName))
def stdout = new StringBuilder(), stderr = new StringBuilder()
proc.consumeProcessOutput(stdout, stderr)
proc.waitForOrKill(1000)
println stdout.toString()
}
//--------- main execution -----------------------------------------------------
def currentDir = new File('.')
currentDir.eachFileRecurse { thisFile ->
fullPath = thisFile.getCanonicalPath()
// ignore stuff in directories we don't care about
if (fullPath ==~ /.*\/_site\/.*/ ||
fullPath ==~ /.*\/\.git\/.*/ ||
fullPath ==~ /.*\/_includes\/.*/ ||
fullPath ==~ /.*\/_layouts\/.*/ ||
fullPath ==~ /.*\/dbdoc\/.*/ ||
fullPath ==~ /.*\/javadoc\/.*/ ) {
return true
}
// We are only interested in files. Don't check this script.
if (thisFile.isFile() && (! thisFile.name.startsWith('listRedirects'))) {
contents = thisFile.text
fileName = thisFile.path.padRight(40)
// check for type 1 redirect
def type1Match = contents =~ /(?m)redirect_to:\s*-*\s*(.*)/
if (type1Match) {
target = type1Match[0][1]
println "type 1 redirect: ${fileName} redirects to ${target}"
}
// check for type 2 redirect
def type2Match = contents =~ /(?m)<redirect>\s*<newLocation>\s*(.*)\s*<\/newLocation>/
if (type2Match) {
target = type2Match[0][1]
println "type 2 redirect: ${fileName} redirects to ${target}"
}
// check for type 3 redirect, and whether it is 'canonicalized'
def type3Match = contents =~ /(?m)<meta http-equiv="refresh"\s*content="\d+;url=(.*)">/
if (type3Match) {
target = type3Match[0][1]
def isCanonical = contents =~/(?m)<link rel="canonical" href="/
def canonicalString = isCanonical ? "(has canonical reference)" : "(DOES NOT HAVE CANONICAL REFERENCE)"
def hasTitle = contents =~/(?m)<title>.*<\/title>/
def titleStatus = hasTitle ? "(has title)" : "(DOES NOT HAVE TITLE)"
println "type 3 redirect: ${fileName} redirects to ${target} ${canonicalString} ${titleStatus}"
}
// check for type 4 redirect - this is a thing where we created a layout that did a redirect. Should not be used.
def type4Match = contents =~ /(?m)redirectUrl: (.*)/
if (type4Match) {
target = type4Match[0][1]
println "type 4 redirect: ${fileName} redirects to ${target} - DO NOT USE THIS REDIRECT TYPE! CHANGE TO TYPE 3 using ./createRedirect.sh"
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/liquibase.github.com.git
[email protected]:mirrors/liquibase.github.com.git
mirrors
liquibase.github.com
LiquiBASE
master

搜索帮助