Blog-Update-Fetching-Script

Blog Update Fetching Script

Introduction

This is an automation script I implemented in the Hexo blog update to automatically fetch blog updates, compare them with previous update statuses, and allow users to manually determine the update status of unfinished and newly added blogs, thus obtaining the new blog update status.

All Blogs are classified into three major categories:

  • ⏸️(Still working)

  • ✅(Mostly finished)

  • ❌(Barely completed)

Preliminaries

ℹ️ For the latest version, we strongly recommend you to run `main.py` (or `run.sh` directly)! The old version of `main.sh` will no longer be maintained.

For the latest version, you need to get the Absolute address of your hexo directories which stores all your Markdown files and replace it with the variable of BLOG_DIR.

For example, in main.py:

1
2
3
4
5
6
7
8
9
#!/home/xiyuanyang/anaconda3/bin/python
# ! ATTENTION: change it to your own python interpreter.
import os
import sys
from datetime import datetime

# Configuration
# ! ATTENTION: replace the BLOG_DIR with your own.
BLOG_DIR = "/mnt/d/Blog/source/_posts"

Usage

For the new version

You can run the original python scripts:

1
python main.py

And you will see the answers and the output! Go to Demo for more details.

Or you can run the bash scripts run.sh to achieve more refined output control!

1
bash run.sh
For the old version (not recommended)

In main.sh, change the directory into your own directory:

1
2
3
DIR="/mnt/d/Blog/source/_posts"

# Change this line into your own directory!

Then create a new dir containing logs.

1
touch log

You need to initialize prev.txt for your own blog!

For this document, please maintain the following format: Each line should include a prefix status emoji and the title name. The prefix status emojis include ✅ and ❌, indicating the completion status of the blog.

An example text is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
AI-Paper-2024
AI-indepth-reading-AlexNet
Above-All
Algorithm-BFS-DFS
Algorithm-BinaryTree
Algorithm-Chunking
Algorithm-Introduction
Algorithm-Memo
Algorithm-Sorting
Bash-commands
Bash-exercises
C-plus-plus-Primer-Plus-tutorial
CMake-tutorial-episode2
CMake-tutorial1
CS294-1-LLM-Reasoning

Please ensure that your output structure maintains alphabetical order. You can use the following command line to achieve this:

1
ls $DIR | grep -v ".*\.md" | grep -v ".*\.sh" > ans.txt

You only need to initialize it once! The scripts will update it later.

For Hexo Blog users, the directory which stores your Blog posts may be like as follows:

  • Several .md files
  • Several directories which has the same name with .md files

The main.sh will automatically get all file names using the grep command:

1
ls $DIR | grep -v ".*\.md" | grep -v ".*\.sh" > ans.txt

grep -v ".*\.sh" is because I add several .sh files into it. You can modify it with your own needs.

Then, the file will compare the new status with the previous status stored in the prev.txt. Then the file will ask users to manually determine the update status of unfinished and newly added blogs.

Finally, the scripts will update prev.txt and generate a new blog status named 20250330_200559.txt and you can see the updated status there!

Demo

demo1
demo2

Enjoy Coding

Discussion

Just for fun, and just for hexo users.

Welcome PRs.


Blog-Update-Fetching-Script
https://xiyuanyang-code.github.io/posts/Blog-Update-Fetching-Script/
Author
Xiyuan Yang
Posted on
March 30, 2025
Updated on
April 28, 2025
Licensed under