Skip to content

Commit

Permalink
generate feed
Browse files Browse the repository at this point in the history
  • Loading branch information
rssh committed Feb 3, 2024
1 parent f26b457 commit 0e370d6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 38 deletions.
2 changes: 2 additions & 0 deletions 2016_03_12_chan-chan-chan.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# chan chan chan

Why channels of channels of channels can be useful? Why we often see statements like `make(chan chan chan int)` in Go code ?

Let's look at example [here](https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/)
Expand Down
2 changes: 1 addition & 1 deletion 2016_05-29-contributing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Some possible contribution tasks
# Some possible contribution tasks

1. More substitutes for Future callback methods. (project = trackedfuture, level = easy)

Expand Down
2 changes: 1 addition & 1 deletion 2016_27_03_back-my-stack-traces.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


# Give my stacktraces back

One of the annoying things when debugging concurrent Scala programs - is luck of stack traces from asynchronous calls
with ```Future```s. Ie. when we span task and receive an exception from one, then it is impossible to find in the exception trace,
Expand Down
17 changes: 0 additions & 17 deletions _config.yml

This file was deleted.

19 changes: 0 additions & 19 deletions chan-chan-chan.md

This file was deleted.

70 changes: 70 additions & 0 deletions scripts/generate-feed.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env -S scala-cli -S 3

//> using scala "3.2.1"
//> using dep "com.mchange::audiofluidity-rss:0.0.6"
//> using dep "com.lihaoyi::os-lib::0.9.3"
//

val blogTitle = "Random notes about programming"
val author = "Ruslan Shevchenko <[email protected]>"
val baseUrl = "https://github.com/rssh/notes"
val feedUrl = "https://rssh.github.io/notes/feed.xml"
val wd = os.pwd
val path = if wd.toString.endsWith("scripts") && os.exists(wd / "generate-feed.sc") then
os.Path(wd.wrapped.getParent)
else if os.exists(wd/"scripts"/"generate-feed.sc") then
wd
else
println(s"Can't determinate directory: should be scripts or current dirrectory, not in ${wd}, exiting")
System.exit(1)
???

import audiofluidity.rss.*
import java.time.*

def extractTitle(lines:IndexedSeq[String]): Option[String] = {
val titleLine = "^title: (.*)$".r
val head1Line = """^\# (.*)$""".r
val head2Line = """^\#\# (.*)$""".r
lines.collectFirst{
case titleLine(title) => title
case head1Line(title) => title
case head2Line(title) => title
}

}

println(s"path=$path")
val items = os.list(path).filter(file =>
os.isFile(file) && file.ext == "md" &&
file.baseName != "README"
).flatMap{ file =>
val dateRegExpr = """([0-9]+)_([0-9]+)_([0-9]+)_(.*)$""".r
file.baseName.toString match
case dateRegExpr(sYear,sMonth,sDay, rest) =>
val (month, day) = if (sMonth.toInt > 12) {
(sDay.toInt, sMonth.toInt)
} else (sMonth.toInt, sDay.toInt)
val year = sYear.toInt
val date = LocalDate.of(year,month,day)
println(s"file=$file, date=$date")
Some((file, date))
case _ =>
println(s"file $file without date prefix, skipping")
None
}.sortBy(_._2).reverse.map{ (file, ctime) =>
val mdContent = os.read.lines(file)
val title = extractTitle(mdContent).getOrElse(file.toString)
val pubDate = ZonedDateTime.of(ctime, LocalTime.MIN, ZoneId.systemDefault)
Element.Item.create(title, s"${baseUrl}/file", "at {}", author, pubDate=Some(pubDate))
}

val channel = Element.Channel.create(blogTitle,feedUrl,"random unsorted notes",items)
println(Element.Rss(channel).asXmlText)
val rss = Element.Rss(channel).asXmlText
val targetDir = path/"_site"
if (!os.exists(targetDir)) {
os.makeDir(targetDir)
}
os.write.over(targetDir/"feed.xml",rss)

0 comments on commit 0e370d6

Please sign in to comment.