mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-15 15:03:17 +00:00
fix: improve file ignore logic and preserve newlines in extracted content
This commit is contained in:
11
cmd/files.go
11
cmd/files.go
@@ -87,11 +87,14 @@ func isIgnored(filePath string, patterns []string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if the pattern matches any part of the file path
|
// Check if the pattern matches the full path or any part of it
|
||||||
|
if matched, _ := filepath.Match(pattern, filePath); matched {
|
||||||
|
return true
|
||||||
|
}
|
||||||
pathParts := strings.Split(filePath, string(os.PathSeparator))
|
pathParts := strings.Split(filePath, string(os.PathSeparator))
|
||||||
for _, part := range pathParts {
|
for i := range pathParts {
|
||||||
matched, err := filepath.Match(pattern, part)
|
partialPath := filepath.Join(pathParts[:i+1]...)
|
||||||
if err == nil && matched {
|
if matched, _ := filepath.Match(pattern, partialPath); matched {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -564,10 +564,15 @@ func ExtractContentWithCSS(content, includeSelector string, excludeSelectors []s
|
|||||||
return "", fmt.Errorf("error extracting content with CSS selector: %v", err)
|
return "", fmt.Errorf("error extracting content with CSS selector: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim whitespace and normalize newlines
|
// Trim leading and trailing whitespace, but preserve internal newlines
|
||||||
selectedContent = strings.TrimSpace(selectedContent)
|
selectedContent = strings.TrimSpace(selectedContent)
|
||||||
selectedContent = strings.ReplaceAll(selectedContent, "\n", "")
|
|
||||||
selectedContent = strings.ReplaceAll(selectedContent, "\t", "")
|
// Normalize newlines
|
||||||
|
selectedContent = strings.ReplaceAll(selectedContent, "\r\n", "\n")
|
||||||
|
selectedContent = strings.ReplaceAll(selectedContent, "\r", "\n")
|
||||||
|
|
||||||
|
// Remove any leading or trailing newlines
|
||||||
|
selectedContent = strings.Trim(selectedContent, "\n")
|
||||||
|
|
||||||
logger.Printf("Extracted content length: %d\n", len(selectedContent))
|
logger.Printf("Extracted content length: %d\n", len(selectedContent))
|
||||||
return selectedContent, nil
|
return selectedContent, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user