-
Notifications
You must be signed in to change notification settings - Fork 19
/
rss.sh
executable file
·53 lines (47 loc) · 1.36 KB
/
rss.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
feed="feed.xml"
website_title="MDH • 前端情报"
website_link="https://fe-cool.github.io/news"
description="MDH • 前端情报"
newest_files=$( \
git ls-files -z 'src/*.md' | \
xargs -0 -n1 -I{} -- git log -1 --format="%at {}" {} | \
sort -r | \
head -n10 | \
cut -d " " -f2-)
items=""
for file in ${newest_files[@]}; do
echo $file
file_path_len=${#file}
file_path_end="$(expr $file_path_len - 7)"
title=$(grep "." $file | head -n1)
file_path="${file:4:$file_path_end}.html"
link="$website_link/$file_path"
html=$(pandoc -f markdown -t html $file)
if [ $file == "src/SUMMARY.md" ]; then
html=$(echo $html|sed 's/.md/.html/g')
fi
date=$(git log -1 --format="%aD" -- $file)
item="
<item>
<title><![CDATA[${title:2}]]></title>
<link>$link</link>
<guid isPermaLink=\"false\">$link</guid>
<pubDate>$date</pubDate>
<description><![CDATA[$html]]></description>
</item>
"
items="$items $item"
done
rss_content="<?xml version=\"1.0\" encoding=\"utf-8\"?><rss xmlns:atom=\"http://www.w3.org/2005/Atom\" version=\"2.0\">
<channel>
<title>$website_title</title>
<atom:link href=\"$website_link/$feed\" rel=\"self\" type=\"application/rss+xml\" />
<link>$website_link</link>
<description>$description</description>
$items
</channel>
</rss>"
echo "$rss_content" > "src/$feed"
echo ""
echo "✨ RSS Done!"