-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(robots-txt): Configurable line-skipping rules
- Loading branch information
1 parent
d0cdd54
commit a1608b8
Showing
3 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/github/alturkovic/robots/txt/LineFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.alturkovic.robots.txt | ||
|
||
interface LineFilter { | ||
fun accept(line: String): Boolean | ||
} | ||
|
||
class LineSizeFilter( | ||
private val maxSize: Int | ||
): LineFilter { | ||
override fun accept(line: String): Boolean = line.length <= maxSize | ||
} | ||
|
||
class RobotsLinesFilter( | ||
private val maxLines: Int | ||
): LineFilter { | ||
private var seenLines = 0 | ||
override fun accept(line: String): Boolean { | ||
return seenLines++ < maxLines | ||
} | ||
} | ||
|
||
class RobotsSizeFilter( | ||
private val maxByteSize: Int | ||
): LineFilter { | ||
private var seenBytes = 0 | ||
override fun accept(line: String): Boolean { | ||
seenBytes += line.length | ||
return seenBytes < maxByteSize | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters