summaryrefslogtreecommitdiff
path: root/internal/showcase/code_extractor.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/showcase/code_extractor.go')
-rw-r--r--internal/showcase/code_extractor.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/internal/showcase/code_extractor.go b/internal/showcase/code_extractor.go
index fbf17f6..92ee1e4 100644
--- a/internal/showcase/code_extractor.go
+++ b/internal/showcase/code_extractor.go
@@ -7,13 +7,8 @@ import (
"os"
"path/filepath"
"strings"
- "time"
)
-func init() {
- rand.Seed(time.Now().UnixNano())
-}
-
// extractCodeSnippet extracts a random code snippet from the repository
func extractCodeSnippet(repoPath string, languages []LanguageStats) (string, string, error) {
if len(languages) == 0 {
@@ -487,10 +482,7 @@ func stripComments(code string) string {
if trimmed == "" {
// Keep empty lines for readability
result = append(result, line)
- } else if strings.HasPrefix(trimmed, "//") ||
- strings.HasPrefix(trimmed, "#") && !strings.HasPrefix(trimmed, "#include") && !strings.HasPrefix(trimmed, "#define") ||
- strings.HasPrefix(trimmed, "<!--") ||
- strings.HasPrefix(trimmed, "*") && len(trimmed) > 1 && trimmed[1] == ' ' {
+ } else if isCommentLine(trimmed) {
// Skip comment lines
continue
} else if strings.HasPrefix(trimmed, "\"\"\"") || strings.HasPrefix(trimmed, "'''") {
@@ -527,6 +519,13 @@ func stripComments(code string) string {
return strings.Join(result, "\n")
}
+func isCommentLine(trimmed string) bool {
+ return strings.HasPrefix(trimmed, "//") ||
+ (strings.HasPrefix(trimmed, "#") && !strings.HasPrefix(trimmed, "#include") && !strings.HasPrefix(trimmed, "#define")) ||
+ strings.HasPrefix(trimmed, "<!--") ||
+ (strings.HasPrefix(trimmed, "*") && len(trimmed) > 1 && trimmed[1] == ' ')
+}
+
// removeCommonIndentation removes common leading whitespace from all lines
func removeCommonIndentation(lines []string) []string {
if len(lines) == 0 {