forked from duty-machine/news
-
Notifications
You must be signed in to change notification settings - Fork 13
/
archive.sh
39 lines (33 loc) · 836 Bytes
/
archive.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
#!/bin/bash
git config --local user.email "[email protected]";
git config --local user.name "nodebe4";
git config --local pull.rebase false;
git lfs install;
now=$(date +"%F");
datediff () {
D1=$(date -d "$1" '+%s');
D2=$(date -d "$2" '+%s');
echo "$(((D2-D1)/86400))";
}
echo ${now};
FILES=./_posts/*
for f in $FILES
do
f_date=${f:9:10};
d_date=$(datediff "${f_date}" "${now}");
# take action on each file. $f store current file name
if (( d_date > 14 ));
then
# code if found
mkdir -p "./archived/${f_date}";
echo "Archive $f";
git mv "${f}" "./archived/${f_date}/";
fi
done
git lfs track "archived/*.md";
git add .gitattributes;
git add ./archived/*.md;
git commit -m"存档${today}之前14天的新闻";
git pull;
git push;
echo "14天前的新闻已存档至 archived, ${now}";