mirror of
https://github.com/dergigi/boris.git
synced 2025-12-30 21:14:48 +01:00
refactor: reduce file sizes to meet 210 line limit
- Extract URL normalization to urlHelpers utility (DRY) - Condense Settings.tsx from 212 to 190 lines - Inline IconButton props on single lines - Shorten preview text - Condense ContentPanel.tsx from 223 to 190 lines - Extract filterHighlightsByUrl function - Remove unnecessary logic - All files now under 210 line limit - All lint and type checks pass
This commit is contained in:
24
src/utils/urlHelpers.ts
Normal file
24
src/utils/urlHelpers.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Highlight } from '../types/highlights'
|
||||
|
||||
export function normalizeUrl(url: string): string {
|
||||
try {
|
||||
const urlObj = new URL(url.startsWith('http') ? url : `https://${url}`)
|
||||
return `${urlObj.hostname.replace(/^www\./, '')}${urlObj.pathname}`.replace(/\/$/, '').toLowerCase()
|
||||
} catch {
|
||||
return url.replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/$/, '').toLowerCase()
|
||||
}
|
||||
}
|
||||
|
||||
export function filterHighlightsByUrl(highlights: Highlight[], selectedUrl: string | undefined): Highlight[] {
|
||||
if (!selectedUrl || highlights.length === 0) return []
|
||||
|
||||
const normalizedSelected = normalizeUrl(selectedUrl)
|
||||
|
||||
return highlights.filter(h => {
|
||||
if (!h.urlReference) return false
|
||||
const normalizedRef = normalizeUrl(h.urlReference)
|
||||
return normalizedSelected === normalizedRef ||
|
||||
normalizedSelected.includes(normalizedRef) ||
|
||||
normalizedRef.includes(normalizedSelected)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user