diff options
author | cassiozareck <121526696+cassiozareck@users.noreply.github.com> | 2023-08-07 16:00:53 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-07 15:00:53 -0400 |
commit | ab0eb1c47b10a1a65f9db0b609fb5339613d1708 (patch) | |
tree | 7078d28e6585ab90cd670a660fd612fff3eac908 /modules/analyze/code_language.go | |
parent | a5d8f95550a7efa17a20a41b4b338616120b6dcb (diff) | |
download | gitea-ab0eb1c47b10a1a65f9db0b609fb5339613d1708.tar.gz gitea-ab0eb1c47b10a1a65f9db0b609fb5339613d1708.zip |
Rename code_langauge.go to code_language.go (#26377)
Diffstat (limited to 'modules/analyze/code_language.go')
-rw-r--r-- | modules/analyze/code_language.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/analyze/code_language.go b/modules/analyze/code_language.go new file mode 100644 index 0000000000..74e7a06d06 --- /dev/null +++ b/modules/analyze/code_language.go @@ -0,0 +1,27 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package analyze + +import ( + "path/filepath" + + "github.com/go-enry/go-enry/v2" +) + +// GetCodeLanguage detects code language based on file name and content +func GetCodeLanguage(filename string, content []byte) string { + if language, ok := enry.GetLanguageByExtension(filename); ok { + return language + } + + if language, ok := enry.GetLanguageByFilename(filename); ok { + return language + } + + if len(content) == 0 { + return enry.OtherLanguage + } + + return enry.GetLanguage(filepath.Base(filename), content) +} |