Skip to content

Qiu-LingYan/pystaticblog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

静态博客站 🚀

一个现代化、高性能的静态博客系统,采用Python构建,专为GitHub Pages优化设计。此博客系统支持Markdown写作,拥有响应式设计,可一键部署到GitHub Pages。

✨ 特性

  • 🎨 现代化设计:渐变色主题,流畅动画,响应式布局
  • 📱 移动优先:完美适配手机、平板、桌面设备
  • 极速加载:静态生成,CDN加速,懒加载图片
  • 🔍 全文搜索:快速查找文章内容
  • 📊 代码高亮:支持100+编程语言
  • 📈 SEO优化:完整的SEO元数据,Open Graph支持
  • 🌐 多语言:支持中英文切换
  • 🎯 零依赖:纯静态文件,无需服务器
  • 📝 Markdown支持:使用Markdown编写文章
  • 🚀 快速部署:一键部署到GitHub Pages

🚀 快速开始

首次使用提示

首次使用本博客系统时,请运行 deploy_helper.py 脚本,按照提示填写GitHub用户名、博客URL、仓库地址等相关资料,这些信息将存储在 config.json 中。

python deploy_helper.py

1. 克隆项目

# 将 yourusername 替换为你的GitHub用户名
git clone https://github.com/yourusername/yourusername.github.io.git
cd yourusername.github.io

2. 安装依赖

确保你已经安装了Python 3.7或更高版本,然后运行以下命令安装依赖:

pip install -r requirements.txt

3. 添加文章

posts/ 目录下创建Markdown文件,文件开头需要包含YAML格式的元数据:

---
title: "文章标题"
date: 2024-08-18
tags: ["标签1", "标签2"]
description: "文章描述"
author: "作者名"
slug: "文章URL别名"
---

# 文章内容

这里是文章内容...

4. 构建博客

# 构建所有文章
python blog_generator.py

# 开发模式(监听文件变化)
python blog_generator.py --watch

# 指定输出目录
python blog_generator.py --output ./my-blog

5. 本地预览

cd output  # 根据实际输出目录调整
python -m http.server 8000
# 访问 http://localhost:8000

📁 项目结构

yourusername.github.io/
├── posts/                    # 文章源文件
├── templates/                # HTML模板
│   ├── base.html            # 基础模板
│   ├── index.html           # 首页模板
│   ├── post.html            # 文章页模板
├── static/                   # 静态资源
│   ├── css/                 
│   │   └── style.css        # 样式文件
│   └── js/                  
│       └── main.js          # 交互脚本
├── output/                   # 生成的静态文件
├── blog_generator.py         # 主程序
├── config.json              # 配置文件
├── requirements.txt         # Python依赖
├── README.md               # 项目说明
└── deploy_helper.py         # 部署辅助脚本

⚙️ 配置说明

编辑 config.json 文件来自定义博客:

{
  "site": {
    "title": "你的博客标题",
    "description": "博客描述",
    "url": "https://yourusername.github.io",
    "author": "作者名"
  },
  "social": {
    "github": "https://github.com/yourusername",
    "twitter": "https://twitter.com/yourusername"
  }
}

📝 写作指南

文章元数据

每篇文章开头必须包含YAML格式的元数据:

---
title: "文章标题"
date: 2024-08-18
tags: ["技术", "Python"]
description: "文章简短描述"
author: "作者名"
slug: "article-slug"  # 可选,自定义URL
---

支持的Markdown语法

  • 标题# 一级标题###### 六级标题

  • 列表- 无序列表1. 有序列表

  • 代码块

    ```python

def hello(): print("Hello, World!")

  • 表格

列1 列2
内容1 内容2

- **数学公式**:
  - 行内公式:`$E = mc^2$`
  - 块级公式:
    
    ```
    $$
    \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
    $$
    ```

## 🚀 部署到GitHub Pages
### 方法1:使用部署辅助脚本(推荐)
运行 `deploy_helper.py` 脚本,按照提示输入GitHub相关信息,即可完成配置更新和博客部署。若首次使用,该脚本会提示你填写必要资料。

```bash
python deploy_helper.py

方法2:GitHub Actions自动部署

  1. Fork本仓库到你的GitHub账户。
  2. 重命名仓库yourusername.github.io
  3. 启用GitHub Pages
    • 进入仓库 Settings → Pages。
    • 选择 Deploy from a branch。
    • 选择 gh-pages 分支。
  4. 推送代码

git add . git commit -m "Initial commit" git push origin main

5. **等待部署**:几分钟后访问 `https://yourusername.github.io`。

### 方法3:手动部署
```bash
# 构建静态文件
python blog_generator.py

# 初始化git仓库
cd output  # 根据实际输出目录调整
git init
git add .
git commit -m "Auto deploy"

<... 3 more lines not shown ...>

About

PyStaticBlog 是一个现代化、高性能的开源静态博客系统,使用 Python 构建,专为 GitHub Pages 优化。支持 Markdown 写作,具备响应式设计、代码高亮等功能,可一键部署到 GitHub Pages,零依赖且支持多语言切换。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors