@ECHO OFF cd C:\Users\RandolfluoPC\Desktop\randolfluoblog color3 ECHO ##########----------~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Randolfluo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~----------########## ECHO. ECHO. :again echo --------------------------------------- echo number = s Local generation echo number = gd Upload to github echo number = others exit echo --------------------------------------- echo please enter your choice:
set /p num= if "%num%"=="s" ( start http://localhost:4000/ hexo s PAUSE ) if "%num%"=="gd" ( hexo g && hexo d PAUSE )
defupdate_markdown_file(file_path): # 读取文件内容 withopen(file_path, 'r', encoding='utf-8') as file: content = file.readlines() # 匹配 date: 行,支持引号和单个数字的月份/日期 date_pattern = re.compile(r'date:\s*[\'"]*(\d{4}[-/]\d{1,2}[-/]\d{1,2})[\'"]*') updated_pattern = re.compile(r'updated:\s*') # 首先找到 date 值 date_value = None for line in content: match = date_pattern.search(line.strip()) # 先去除行首尾的空格 ifmatch: raw_date = match.group(1) date_value = normalize_date(raw_date) if date_value: # 确保日期格式化成功 break # 如果找到了有效的 date 值,则更新 updated 字段 if date_value: for i, line inenumerate(content): if updated_pattern.search(line.strip()): # 先去除行首尾的空格 # 保持原有的缩进 leading_spaces = re.match(r'^\s*', line).group(0) # 打印修改信息 print(f"\n文件: {file_path}") print(f"找到的date值: {date_value}") print(f"修改前updated行: {line.strip()}") # 使用 date 值更新 updated 字段,保持原有缩进 content[i] = f'{leading_spaces}updated: {date_value}\n' print(f"修改后updated行: {content[i].strip()}") break # 写回文件 withopen(file_path, 'w', encoding='utf-8') as file: file.writelines(content) else: print(f"\n文件: {file_path} 中未找到有效的date字段")
defprocess_directory(directory): """ 处理目录下的所有markdown文件 """ for root, _, files in os.walk(directory): for file in files: if file.lower().endswith(('.md', '.markdown')): file_path = os.path.join(root, file) update_markdown_file(file_path)