0%

embeding doc of jackfrued/Python-100-Days

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
#!/bin/bash

# Initialize the timestamp variable with the current date and time
tsf=$(mktemp)
echo $(date -u -d "2024-04-09 23:44:24" +%s) >$tsf
echo "tsf=$tsf"

# Function to prepend text to a file
prepend() {
local tempFile
tempFile=$(mktemp)
echo "$2" > "$tempFile"
cat "$1" >> "$tempFile"
mv "$tempFile" "$1"
}

# Function to generate the content to be prepended
generate_content() {
filename=$(basename "$1" .md)

# Increment the timestamp by one second
ts=$(($(cat $tsf) - 1))

# Convert the timestamp to the date format
date=$(date -u -d "@$ts" +"%Y-%m-%d %T")
echo $ts >$tsf
echo "---
title: $filename
categories:
- [jackfrued-Python-temp]
date: $date
draft: false
tags:
---
"
}

CWD="$(pwd)"

cd source/_posts/Python-100-Days
git reset --hard
rm -r res
rm -r "公开课"
rm -r "番外篇"
rm *.md
# Main script
for file in $(find . -name "*.md"|grep Day |sort); do
content=$(generate_content "$file")
prepend "$file" "$content"
done