fixed 文章结构
This commit is contained in:
1 parent
6ad43b2c08
commit
ba93d0faa4
813 files changed
+243
-164
No files matched your search
@@ -1,58 +0,0 @@
|
||||
from hashlib import sha1
|
||||
import hmac
|
||||
import requests
|
||||
import json
|
||||
import urllib
|
||||
import os
|
||||
|
||||
def dogecloud_api(api_path, data={}, json_mode=False):
|
||||
"""
|
||||
调用多吉云API。
|
||||
|
||||
:param api_path: 调用的 API 接口地址,包含 URL 请求参数 QueryString。
|
||||
:param data: POST 的数据,字典格式。
|
||||
:param json_mode: 数据 data 是否以 JSON 格式请求,默认为 false 则使用表单形式。
|
||||
|
||||
:return dict: 返回的数据。
|
||||
"""
|
||||
access_key = os.environ.get('DOGECLOUD_ACCESS_KEY') # 从环境变量获取 AccessKey
|
||||
secret_key = os.environ.get('DOGECLOUD_SECRET_KEY') # 从环境变量获取 SecretKey
|
||||
|
||||
if not access_key or not secret_key:
|
||||
raise ValueError("Access Key or Secret Key is not set in environment variables.")
|
||||
|
||||
body = ''
|
||||
mime = ''
|
||||
if json_mode:
|
||||
body = json.dumps(data)
|
||||
mime = 'application/json'
|
||||
else:
|
||||
body = urllib.parse.urlencode(data)
|
||||
mime = 'application/x-www-form-urlencoded'
|
||||
|
||||
sign_str = api_path + "\n" + body
|
||||
signed_data = hmac.new(secret_key.encode('utf-8'), sign_str.encode('utf-8'), sha1)
|
||||
sign = signed_data.digest().hex()
|
||||
authorization = 'TOKEN ' + access_key + ':' + sign
|
||||
|
||||
response = requests.post('https://api.dogecloud.com' + api_path, data=body, headers={
|
||||
'Authorization': authorization,
|
||||
'Content-Type': mime
|
||||
})
|
||||
return response.json()
|
||||
|
||||
# 从环境变量中获取 URL 列表,使用逗号分隔
|
||||
url_list_env = os.environ.get('CDN_URL_LIST')
|
||||
if not url_list_env:
|
||||
raise ValueError("CDN_URL_LIST is not set in environment variables.")
|
||||
|
||||
url_list = url_list_env.split(',')
|
||||
|
||||
api = dogecloud_api('/cdn/refresh/add.json', {
|
||||
'rtype': 'path',
|
||||
'urls': json.dumps(url_list)
|
||||
})
|
||||
if api['code'] == 200:
|
||||
print(api['data']['task_id'])
|
||||
else:
|
||||
print("API failed: " + api['msg'])
|
||||
@@ -5,7 +5,7 @@ const path = require('path');
|
||||
const https = require('https');
|
||||
const http = require('http');
|
||||
|
||||
const linksPath = path.join(__dirname, '../themes/Ying/data/links.yaml');
|
||||
const linksPath = path.join(__dirname, '../data/links.yaml');
|
||||
const outputPath = path.join(__dirname, '../static/link_status.json');
|
||||
|
||||
// Ensure static dir exists
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const CONTENT_DIR = path.join(__dirname, '../content/post');
|
||||
|
||||
async function processFiles(dir) {
|
||||
const files = await fs.promises.readdir(dir);
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dir, file);
|
||||
const stats = await fs.promises.stat(filePath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
await processFiles(filePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!file.endsWith('.md')) continue;
|
||||
|
||||
let content = await fs.promises.readFile(filePath, 'utf8');
|
||||
|
||||
// Match Front Matter (handling BOM)
|
||||
const match = content.match(/^[\ufeff]?---\r?\n([\s\S]*?)\r?\n---/);
|
||||
if (!match) {
|
||||
// Try matching without BOM anchor if needed, or maybe just log
|
||||
// console.log(`[Skip] ${file}: No front matter found`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const fmContent = match[1];
|
||||
const lines = fmContent.split(/\r?\n/);
|
||||
const keyMap = new Map();
|
||||
const linesToDelete = new Set();
|
||||
|
||||
// Identify keys and their positions
|
||||
lines.forEach((line, index) => {
|
||||
const keyMatch = line.match(/^([a-zA-Z0-9_-]+):/);
|
||||
if (keyMatch) {
|
||||
const key = keyMatch[1];
|
||||
if (!keyMap.has(key)) {
|
||||
keyMap.set(key, []);
|
||||
}
|
||||
keyMap.get(key).push(index);
|
||||
}
|
||||
});
|
||||
|
||||
let modified = false;
|
||||
|
||||
// Check for duplicates
|
||||
for (const [key, indices] of keyMap.entries()) {
|
||||
if (indices.length > 1) {
|
||||
// Keep the LAST occurrence
|
||||
for (let i = 0; i < indices.length - 1; i++) {
|
||||
linesToDelete.add(indices[i]);
|
||||
}
|
||||
modified = true;
|
||||
console.log(`[Fixing] ${file}: Removing duplicate key '${key}' at lines ${indices.slice(0, -1).join(', ')} (keeping line ${indices[indices.length - 1]})`);
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
const newFmLines = lines.filter((_, index) => !linesToDelete.has(index));
|
||||
const newFm = newFmLines.join('\n');
|
||||
// Reconstruct file
|
||||
const newContent = content.replace(match[0], `---\n${newFm}\n---`);
|
||||
await fs.promises.writeFile(filePath, newContent, 'utf8');
|
||||
console.log(`[Success] Updated ${file}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Starting YAML Fixer...');
|
||||
processFiles(CONTENT_DIR).catch(console.error);
|
||||
@@ -18,7 +18,7 @@
|
||||
.\scripts\update_link_lite_json.ps1
|
||||
#>
|
||||
|
||||
$yamlPath = Join-Path $PSScriptRoot "..\themes\Ying\data\links.yaml"
|
||||
$yamlPath = Join-Path $PSScriptRoot "..\data\links.yaml"
|
||||
$jsonPath = Join-Path $PSScriptRoot "..\themes\Ying\static\json\link_lite.json"
|
||||
|
||||
Write-Host "Reading $yamlPath..."
|
||||
|
||||
Reference in new issue
Block a user