Skip to content

Commit

Permalink
Add option to strip Royal Road site title suffix from filename (#33)
Browse files Browse the repository at this point in the history
* Add option to strip Royal Road site title suffix from filename

* Adjust option and invert logic so it's a keep instead of skip option

* Remove the --keep-site-title option again and just always remove the title
  • Loading branch information
trilader authored Jan 19, 2024
1 parent d05a0b0 commit 7017d77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/com/aivean/royalroad/Args.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ class Args(args: Seq[String]) extends ScallopConf(args) {

object Args {
val urlValidationRegex = "(https?://(www\\.)?royalroadl?.com/fiction/\\d+)(/.*)?"
}
}
4 changes: 3 additions & 1 deletion src/main/scala/com/aivean/royalroad/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ object Main extends App {
chapQ.put(None)
}

val filename = title.replaceAll("[^\\w\\d]+", "_") + {
val filesafeTitle = title.stripSuffix(" | Royal Road").replaceAll("[^\\w\\d]+", "_")

val filename = filesafeTitle + {
// when chapter range is specified, add it to the filename
if (chapUrls.size != chapUrlsConstrained.size) {
val firstChapter = chapUrls.indexOf(chapUrlsConstrained.head)
Expand Down

0 comments on commit 7017d77

Please sign in to comment.