Skip to content

Commit 0e370d6

Browse files
committed
generate feed
1 parent f26b457 commit 0e370d6

File tree

6 files changed

+74
-38
lines changed

6 files changed

+74
-38
lines changed

2016_03_12_chan-chan-chan.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# chan chan chan
2+
13
Why channels of channels of channels can be useful? Why we often see statements like `make(chan chan chan int)` in Go code ?
24

35
Let's look at example [here](https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/)

2016_05-29-contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
Some possible contribution tasks
2+
# Some possible contribution tasks
33

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

2016_27_03_back-my-stack-traces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
2+
# Give my stacktraces back
33

44
One of the annoying things when debugging concurrent Scala programs - is luck of stack traces from asynchronous calls
55
with ```Future```s. Ie. when we span task and receive an exception from one, then it is impossible to find in the exception trace,

_config.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

chan-chan-chan.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/generate-feed.sc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env -S scala-cli -S 3
2+
3+
//> using scala "3.2.1"
4+
//> using dep "com.mchange::audiofluidity-rss:0.0.6"
5+
//> using dep "com.lihaoyi::os-lib::0.9.3"
6+
//
7+
8+
val blogTitle = "Random notes about programming"
9+
val author = "Ruslan Shevchenko <[email protected]>"
10+
val baseUrl = "https://github.com/rssh/notes"
11+
val feedUrl = "https://rssh.github.io/notes/feed.xml"
12+
val wd = os.pwd
13+
val path = if wd.toString.endsWith("scripts") && os.exists(wd / "generate-feed.sc") then
14+
os.Path(wd.wrapped.getParent)
15+
else if os.exists(wd/"scripts"/"generate-feed.sc") then
16+
wd
17+
else
18+
println(s"Can't determinate directory: should be scripts or current dirrectory, not in ${wd}, exiting")
19+
System.exit(1)
20+
???
21+
22+
import audiofluidity.rss.*
23+
import java.time.*
24+
25+
def extractTitle(lines:IndexedSeq[String]): Option[String] = {
26+
val titleLine = "^title: (.*)$".r
27+
val head1Line = """^\# (.*)$""".r
28+
val head2Line = """^\#\# (.*)$""".r
29+
lines.collectFirst{
30+
case titleLine(title) => title
31+
case head1Line(title) => title
32+
case head2Line(title) => title
33+
}
34+
35+
}
36+
37+
println(s"path=$path")
38+
val items = os.list(path).filter(file =>
39+
os.isFile(file) && file.ext == "md" &&
40+
file.baseName != "README"
41+
).flatMap{ file =>
42+
val dateRegExpr = """([0-9]+)_([0-9]+)_([0-9]+)_(.*)$""".r
43+
file.baseName.toString match
44+
case dateRegExpr(sYear,sMonth,sDay, rest) =>
45+
val (month, day) = if (sMonth.toInt > 12) {
46+
(sDay.toInt, sMonth.toInt)
47+
} else (sMonth.toInt, sDay.toInt)
48+
val year = sYear.toInt
49+
val date = LocalDate.of(year,month,day)
50+
println(s"file=$file, date=$date")
51+
Some((file, date))
52+
case _ =>
53+
println(s"file $file without date prefix, skipping")
54+
None
55+
}.sortBy(_._2).reverse.map{ (file, ctime) =>
56+
val mdContent = os.read.lines(file)
57+
val title = extractTitle(mdContent).getOrElse(file.toString)
58+
val pubDate = ZonedDateTime.of(ctime, LocalTime.MIN, ZoneId.systemDefault)
59+
Element.Item.create(title, s"${baseUrl}/file", "at {}", author, pubDate=Some(pubDate))
60+
}
61+
62+
val channel = Element.Channel.create(blogTitle,feedUrl,"random unsorted notes",items)
63+
println(Element.Rss(channel).asXmlText)
64+
val rss = Element.Rss(channel).asXmlText
65+
val targetDir = path/"_site"
66+
if (!os.exists(targetDir)) {
67+
os.makeDir(targetDir)
68+
}
69+
os.write.over(targetDir/"feed.xml",rss)
70+

0 commit comments

Comments
 (0)