Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat&pref: 优化样式与新增检测脚本 #2

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .action_scripts/check-local-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const fs = require('fs');
const glob = require('glob');
const path = require('path');

// 修改正则表达式,以匹配绝对路径或包含驱动器的路径
const pattern = /(?:[A-Z]:\\)/g;
const files = ['**/*.html', '**/*.js', '**/*.css'];

// 自定义跳过文件列表(使用相对路径)
const skipFiles = [
'Tools/Fufu_Tools/minimum/index.html',
];

// 自定义跳过文件夹列表(使用相对路径)
const skipFolders = [
'Tools/Fufu_Tools/wiki',
];

let foundPath = false; // 用于跟踪是否已经找到路径

files.forEach(globPattern => {
const filePaths = glob.sync(globPattern, { nodir: true });
filePaths.forEach(filePath => {
// 获取相对路径,并标准化路径分隔符
const relativePath = path.relative(process.cwd(), filePath).replace(/\\/g, '/');

// 检查是否在跳过的文件夹中
if (skipFolders.some(folder => relativePath.startsWith(folder.replace(/\\/g, '/')))) {
return;
}

// 检查是否在跳过的文件列表中
if (skipFiles.includes(relativePath)) {
return;
}

const content = fs.readFileSync(filePath, 'utf8');
const lines = content.split('\n');

lines.forEach(line => {
let match;
while ((match = pattern.exec(line)) !== null) {
// 检测是否是绝对路径
if (/^[A-Z]:\\/.test(match[0]) || /^\/[^\/:*?"<>|\r\n]/.test(match[0])) {
// 打印检测到的路径
console.error(`✕ 在 ${filePath} 检测到本地路径: ${match[0]}`);
foundPath = true;
return; // 找到路径后,跳过该文件的其他行
}
}
});
});
});

// 在所有文件处理完成后输出结果
if (foundPath) {
process.exit(1); // 如果发现路径,退出并且有非零状态码
} else {
console.log('✓ 所有文件检测完毕,未发现本地路径');
}
69 changes: 69 additions & 0 deletions .action_scripts/link_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import re
import sys
import requests

DIRECTORY = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # 指定要检查的目录为所在目录上级目录
IGNORE_FOLDERS = ['music_games'] # 忽略的文件夹
IGNORE_FILES = ['Duck Parkour.html'] # 忽略的文件
IGNORE_URLS = [
# 常时
'https://duckduckstudio.github.io/yazicbs.github.io/Interesting/sounds/*.mp3',
'https://duckduckstudio.github.io/yazicbs.github.io/music_games/photos/show.png'
] # 忽略的链接

# 更新后的链接正则表达式
URL_REGEX = re.compile(r'"https://[^\'"\n\r\s<>]*(?=[\'"])')

def check_link(url):
if url in IGNORE_URLS:
return 'Ignored URL', 'ignored'
try:
response = requests.head(url, allow_redirects=True)
if response.status_code == 412:
return '412 Precondition Failed', 'pass'
elif response.status_code == 404:
return '404 Not Found', 'faild'
elif response.status_code == 200:
return 200, 'pass'
return response.status_code, 'pass'
except requests.ConnectionError:
return 'Connection Error', 'pass'
except requests.Timeout:
return 'Timeout', 'faild'
except requests.RequestException as e:
return f'Error: {str(e)}', 'faild'

def check_files():
for root, dirs, files in os.walk(DIRECTORY):
# 忽略指定的文件夹
if any(ignore in root for ignore in IGNORE_FOLDERS):
continue

for file in files:
# 忽略指定的文件
if file in IGNORE_FILES or not file.endswith(('.html', '.css', '.js')):
continue

file_path = os.path.join(root, file)
relative_file_path = os.path.relpath(file_path, DIRECTORY) # 计算相对路径
with open(file_path, 'r', encoding='utf-8') as f:
for line_number, line in enumerate(f, start=1):
urls = URL_REGEX.findall(line)
for url in urls:
if url.startswith(("'", '"')):
url = url.strip('\'"') # 去除引号
status_code, status_message = check_link(url)
if status_message == 'ignored':
print(f'\n[IGNORED] 文件: {relative_file_path} | 行号: {line_number} | 链接: {url} | 返回代码: {status_code}')
elif status_code == 200:
print('*', end='')
else:
if status_message == "pass":
print(f'\n[WARNING] 文件: {relative_file_path} | 行号: {line_number} | 链接: {url} | 返回代码: {status_code}')
elif status_message == "faild":
print(f'\n[ERROR] 文件: {relative_file_path} | 行号: {line_number} | 链接: {url} | 返回代码: {status_code}')
sys.exit(1)

if __name__ == '__main__':
check_files()
64 changes: 64 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_feedback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: '🐛 BUG反馈'
description: 向我们反馈你遇到的错误
title: "[BUG]: "
labels: ["bug", "DEV-需要注意", "DEV-未经测试"]
body:
- type: checkboxes
attributes:
label: 在继续之前,请确认以下内容
description: 在发布您的问题之前,请确认以下内容。
options:
- label: 我已经搜索过已存在的问题,并没有存在相同的正在进行中/重复/已解决的问题
required: true
- label: 我知道由于作者精力有限,可能不会处理手机端的显示错误
required: true
- type: dropdown
attributes:
label: 选择一个问题类别
description: 你遇到了什么样的问题?
options:
- 链接问题
- 显示问题
- 内容问题
- 访问问题
- JS相关问题
- 其他
validations:
required: true
- type: textarea
attributes:
label: 描述你遇到的问题
placeholder: 请在此简要描述您的问题
validations:
required: true
- type: textarea
attributes:
label: 描述如何重现你遇到的问题
placeholder: 如何重现该问题?(填写此字段对问题调查很有帮助!)
validations:
required: true
- type: textarea
attributes:
label: 实际行为
placeholder: 你遇到的情况是什么样的
validations:
required: false
- type: textarea
attributes:
label: 预期行为
placeholder: 正常情况下应该是什么样的
validations:
required: false
- type: textarea
attributes:
label: 确认相关信息
description: 请将页面在控制台的输出放到这里 (F12)
render: raw
validations:
required: false
- type: textarea
attributes:
label: 屏幕截图或日志
description: 请上传你记录的日志/屏幕截图,因为它们将帮助我们找到问题的根本原因。
validations:
required: true
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: 查看已经打开的问题
url: https://github.com/fjwxzde/fjwxzde.github.io/issues
about: 请确认你的问题没有与已存在的问题重复。
40 changes: 40 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "🚀 新功能请求 / 想法"
title: "[Feat]: "
description: 提出新功能或改进建议 (这并不意味着你必须实现它)。
labels: ["新功能","DEV-需要注意"]
body:
- type: markdown
attributes:
value: |
感谢您抽出时间与我们讨论新功能的想法!
- type: dropdown
attributes:
label: 选择一个类别
description: 是什么类型的新功能捏?
options:
- 友情链接
- 搜索引擎抓取
- 页面交互
- 页面显示
- 控制台输出
- 其他
validations:
required: true
- type: textarea
attributes:
label: 对新功能/建议的描述
placeholder: 告诉我们你想实现什么。
validations:
required: true
- type: textarea
attributes:
label: 为什么需要实现此功能
placeholder: 告诉我们为什么需要这个功能?能带来什么好处?
validations:
required: true
- type: textarea
attributes:
label: 对于实施该功能的方法的建议
placeholder: 建议我们如何实现这一点
validations:
required: false
14 changes: 14 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### 检查清单
- [ ] 有链接Issue吗? -- Resolve <!--←如有请在这里填写具体链接的议题,例如 #1314-->
- [ ] 你检查过没有其他重复的 [拉取请求](https://github.com/fjwxzde/fjwxzde.github.io/pulls) 吗?
- [ ] 此拉取请求仅针对一个问题/功能吗?
- [ ] 你验证过你的修改吗?
- [ ] 你确定你的描述足以让开发人员理解你的意图以及解决方案?
- [ ] 你知晓关于网站内容的拉取请求通常不会通过审查

### 修改说明

<!--在这里尽可能详细的描述你做的修改,以便开发人员审查你的修改。-->

---

28 changes: 28 additions & 0 deletions .github/workflows/check-local-paths.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 检查本地路径

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
check-local-paths:
runs-on: ubuntu-latest

steps:
- name: 检出代码
uses: actions/checkout@v4

- name: 设置 Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: 安装依赖
run: npm install glob

- name: 运行本地路径检查
run: node ./.action_scripts/check-local-paths.js
33 changes: 33 additions & 0 deletions .github/workflows/check_url_visit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 检查链接有效性

on:
schedule: # 夜间执行
- cron: '0 0 * * *'
workflow_dispatch: # 手动执行
pull_request: # PR执行
branches:
- main
push: # Push到main执行
branches:
- main

jobs:
check-url:
runs-on: ubuntu-latest

steps:
- name: 检出代码
uses: actions/checkout@v4

- name: 设置 Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: 安装依赖
run: |
python -m pip install --upgrade pip
pip install requests

- name: 检查链接有效性
run: python ./.action_scripts/link_checker.py
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 王药师的个人网站

> Code by @DuckDuckStudio.

| 部署 | 检查链接有效性 | 检查本地路径 |
|-----|-----|-----|
| [![pages-build-deployment](https://github.com/fjwxzde/fjwxzde.github.io/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/fjwxzde/fjwxzde.github.io/actions/workflows/pages/pages-build-deployment) | [![检查链接有效性](https://github.com/fjwxzde/fjwxzde.github.io/actions/workflows/check_url_visit.yml/badge.svg)](https://github.com/fjwxzde/fjwxzde.github.io/actions/workflows/check_url_visit.yml) | [![检查本地路径](https://github.com/fjwxzde/fjwxzde.github.io/actions/workflows/check-local-paths.yml/badge.svg)](https://github.com/fjwxzde/fjwxzde.github.io/actions/workflows/check-local-paths.yml) |
File renamed without changes
16 changes: 3 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<!-- Code by Duck Studio -->
<!-- ©鸭鸭「カモ」 (包括图片) -->
<!-- (c) 鸭鸭「カモ」 (包括图片) -->

<html lang="zh">
<head>
<!-- 在这里修改页面标题 -->
Expand Down Expand Up @@ -37,17 +38,6 @@
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

h1 {
color: #333;
font-size: 40px;
}

h2 {
color: #333;
font-size: 24px; /* 调整标题文本大小 */
margin-bottom: 10px; /* 调整标题与下方段落的间距 */
}

img {
max-width: 100%;
height: auto;
Expand All @@ -73,7 +63,7 @@ <h1>王药师的个人网站</h1>

<!-- 在这里放文章内容 -->
<div class="center-text">
<img src="photos/太极.png" alt="太极" width="30%" height="30%">
<img src="assets/pic/太极.png" alt="太极" width="30%" height="30%">
</div>
<p>欢迎合作、意见和建议!</p>
<div class="center-text" style="border: 2px solid black;border-color: rgb(255, 0, 0);">
Expand Down