更改:readme显示顺序
This commit is contained in:
parent
36b8cb828c
commit
7968d1ad46
|
@ -134,8 +134,9 @@ func GetReadmeContents(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
ref := ctx.Params(":ref")
|
||||
readmePath := "README.md"
|
||||
readmezhPath := ""
|
||||
readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"}
|
||||
readmePath := ""
|
||||
readmePathInArrIndex := 0
|
||||
filesListInterface, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err)
|
||||
|
@ -144,25 +145,19 @@ func GetReadmeContents(ctx *context.APIContext) {
|
|||
filesList, ok := filesListInterface.([]*api.ContentsResponse)
|
||||
if ok {
|
||||
for _, file := range filesList {
|
||||
if strings.ToLower(file.Name) == "readme.md" {
|
||||
readmePath = file.Name
|
||||
}
|
||||
if strings.ToLower(file.Name) == "readme_zh.md" {
|
||||
readmezhPath = file.Name
|
||||
}
|
||||
if strings.ToLower(file.Name) == "readme_cn.md" {
|
||||
readmezhPath = file.Name
|
||||
}
|
||||
if strings.ToLower(file.Name) == "readme" {
|
||||
readmePath = file.Name
|
||||
for i, sortItem := range readmeSortArr {
|
||||
if strings.ToLower(file.Name) == sortItem {
|
||||
if readmePath != "" && readmePathInArrIndex > i {
|
||||
continue
|
||||
} else {
|
||||
readmePathInArrIndex = i
|
||||
readmePath = file.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if readmezhPath != "" {
|
||||
readmePath = readmezhPath
|
||||
}
|
||||
|
||||
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, readmePath, ref); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetContentsOrList", err)
|
||||
|
@ -193,8 +188,9 @@ func GetReadmeContentsByPath(ctx *context.APIContext) {
|
|||
}
|
||||
treePath := ctx.Params("*")
|
||||
ref := ctx.Params(":ref")
|
||||
readmePath := "README.md"
|
||||
readmezhPath := ""
|
||||
readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"}
|
||||
readmePath := ""
|
||||
readmePathInArrIndex := 0
|
||||
filesListInterface, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err)
|
||||
|
@ -203,25 +199,19 @@ func GetReadmeContentsByPath(ctx *context.APIContext) {
|
|||
filesList, ok := filesListInterface.([]*api.ContentsResponse)
|
||||
if ok {
|
||||
for _, file := range filesList {
|
||||
if strings.ToLower(file.Name) == "readme.md" {
|
||||
readmePath = file.Name
|
||||
}
|
||||
if strings.ToLower(file.Name) == "readme_zh.md" {
|
||||
readmezhPath = file.Name
|
||||
}
|
||||
if strings.ToLower(file.Name) == "readme_ch.md" {
|
||||
readmezhPath = file.Name
|
||||
}
|
||||
if strings.ToLower(file.Name) == "readme" {
|
||||
readmePath = file.Name
|
||||
for i, sortItem := range readmeSortArr {
|
||||
if strings.ToLower(file.Name) == sortItem {
|
||||
if readmePath != "" && readmePathInArrIndex > i {
|
||||
continue
|
||||
} else {
|
||||
readmePathInArrIndex = i
|
||||
readmePath = file.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if readmezhPath != "" {
|
||||
readmePath = readmezhPath
|
||||
}
|
||||
|
||||
newTreePath := treePath + "/" + readmePath
|
||||
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, newTreePath, ref); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
|
|
Loading…
Reference in New Issue