forked from forgejo/forgejo
Support localized README (#20508)
* Support localized README * Slightly simplify getting the readme file and add some tests. Ensure that i18n also works for docs/ etc. Signed-off-by: Andrew Thornton <art27@cantab.net> * Update modules/markup/renderer.go * Update modules/markup/renderer.go * Update modules/markup/renderer.go Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
335e918b11
commit
c35535ce07
4 changed files with 182 additions and 92 deletions
|
@ -310,14 +310,9 @@ func IsMarkupFile(name, markup string) bool {
|
|||
}
|
||||
|
||||
// IsReadmeFile reports whether name looks like a README file
|
||||
// based on its name. If an extension is provided, it will strictly
|
||||
// match that extension.
|
||||
// Note that the '.' should be provided in ext, e.g ".md"
|
||||
func IsReadmeFile(name string, ext ...string) bool {
|
||||
// based on its name.
|
||||
func IsReadmeFile(name string) bool {
|
||||
name = strings.ToLower(name)
|
||||
if len(ext) > 0 {
|
||||
return name == "readme"+ext[0]
|
||||
}
|
||||
if len(name) < 6 {
|
||||
return false
|
||||
} else if len(name) == 6 {
|
||||
|
@ -325,3 +320,27 @@ func IsReadmeFile(name string, ext ...string) bool {
|
|||
}
|
||||
return name[:7] == "readme."
|
||||
}
|
||||
|
||||
// IsReadmeFileExtension reports whether name looks like a README file
|
||||
// based on its name. It will look through the provided extensions and check if the file matches
|
||||
// one of the extensions and provide the index in the extension list.
|
||||
// If the filename is `readme.` with an unmatched extension it will match with the index equaling
|
||||
// the length of the provided extension list.
|
||||
// Note that the '.' should be provided in ext, e.g ".md"
|
||||
func IsReadmeFileExtension(name string, ext ...string) (int, bool) {
|
||||
if len(name) < 6 || name[:6] != "readme" {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
for i, extension := range ext {
|
||||
if name[6:] == extension {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
|
||||
if name[6] == '.' {
|
||||
return len(ext), true
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue