Commit 961225
2026-01-30 02:08:26 Terry: -/-| /dev/null .. pelican安装简要配置说明.md | |
| @@ 0,0 1,219 @@ | |
| + | # Pelican安装简要配置说明 |
| + | |
| + | # Pelican 安装简要配置说明 |
| + | |
| + | ## 环境准备 |
| + | |
| + | ### 安装miniconda |
| + | |
| + | 下载最新版本miniconda |
| + | |
| + | ```bash |
| + | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh |
| + | ``` |
| + | |
| + | ### 建立虚拟环境 |
| + | |
| + | ```bash |
| + | conda create -n pelicanenv # pelicanenv 为环境名称 |
| + | ``` |
| + | |
| + | ### 激活虚拟环境 |
| + | |
| + | ```bash |
| + | conda ativate pelicanenv |
| + | ``` |
| + | |
| + | ## 安装软件包 |
| + | |
| + | ### 安装pelican |
| + | |
| + | 此处使用最新版: |
| + | |
| + | ```bash |
| + | conda install conda-forge::pelican |
| + | ``` |
| + | |
| + | ### 安装nginx |
| + | |
| + | ```bash |
| + | apt-get install nginx |
| + | ``` |
| + | |
| + | ## 创建项目 |
| + | |
| + | ```bash |
| + | mkdir /xxx/xxx # 创建项目目录 |
| + | cd /xxx/xxx # 进入项目目录 |
| + | pelican-quickstart # 生成pelican 项目 |
| + | ``` |
| + | |
| + | *安装过程过,会有很多需要你输入的配置项,如果不知道怎么填就直接忽略或者选择n,因为这些配置项在后面可以自己手动再添加的。* |
| + | |
| + | 创建完成后生成的目录结构如下: |
| + | |
| + | ``` |
| + | . |
| + | ├── Makefile |
| + | ├── content/ |
| + | ├── develop_server.sh |
| + | ├── fabfile.py |
| + | ├── output/ |
| + | ├── pelicanconf.py |
| + | └── publishconf.py |
| + | ``` |
| + | |
| + | 所有文字,都保存在content 目录下。 |
| + | |
| + | 建议使用markdown来写文章。 |
| + | |
| + | ### 创建第一篇文章 |
| + | |
| + | ``` |
| + | touch xxx.md |
| + | ``` |
| + | |
| + | 模板参考 |
| + | |
| + | ```模板参考 |
| + | Title: 这是我的第一篇技术博客 |
| + | Date: 2019-04-24 13:47:06 |
| + | Category: 技术 |
| + | Tags: python |
| + | Slug: hello-world |
| + | Summary: 这是我的第一篇技术博客,欢迎捧场 |
| + | |
| + | |
| + | 这是我的第一篇技术博客,欢迎捧场,第一次写文章,还没想好怎么写,所有就随便写了一点儿。 |
| + | ``` |
| + | |
| + | ### 生成静态文件 |
| + | |
| + | ```bash |
| + | pelican content |
| + | ``` |
| + | |
| + | ### 启动测试服务 |
| + | |
| + | Pelican 自己内置了一个HTTP Server,但是除非是本地开发和测试环境,否则不建议直接使用测试服务 |
| + | |
| + | ```bash |
| + | pelican --listen |
| + | ``` |
| + | |
| + | ### 配置nginx |
| + | |
| + | ```bash |
| + | vim /etc/nginx/sites-available/default |
| + | ``` |
| + | |
| + | ## 主题安装 |
| + | |
| + | ### 下载主题 |
| + | |
| + | ```bash |
| + | git clone --recursive https://github.com/getpelican/pelican-themes ~/pelican-themes |
| + | ``` |
| + | |
| + | ### 安装主题 |
| + | |
| + | ```bash |
| + | pelican-themes -i pelican-themes/gum |
| + | ``` |
| + | |
| + | ### 启用主题 |
| + | |
| + | 编辑 pelicanconf.py |
| + | |
| + | ```bash |
| + | vim pelicanconf.py |
| + | ``` |
| + | |
| + | ```python |
| + | THEME = "gum" |
| + | ``` |
| + | |
| + | 重新生成静态文件 |
| + | |
| + | ```bash |
| + | pelican-themes -l |
| + | ``` |
| + | |
| + | 查看已经安装可用的主题 |
| + | |
| + | ```bash |
| + | pelican-themes -l |
| + | ``` |
| + | |
| + | ## 导入wordpress 文章 |
| + | |
| + | 先将wordpress 文章导出为xxxx.xml |
| + | |
| + | 然后导入pelican |
| + | |
| + | ```bash |
| + | pelican-import --blogger -o ~/output ~/posts.xml |
| + | ``` |
| + | |
| + | 导入后,有大量的rst 文件 |
| + | |
| + | rst 文中slug 字段由于文章名称是中的可能出现乱码,造成前端无法直接访问 |
| + | |
| + | 需要处理一下相关链接后,再生成相关相关静态页面 |
| + | |
| + | 可以使用以下python 脚本: |
| + | |
| + | ```python |
| + | # -*- coding: utf-8 -*- |
| + | import os |
| + | |
| + | def find_slug_lines(file_path): |
| + | # 打开文件并逐行读取 |
| + | with open(file_path, "r", ) as file: |
| + | target_line_number = None |
| + | target_line = None |
| + | #alines = file.readlines() |
| + | for line_number, line in enumerate(file, start=1): |
| + | #alines = file.readlines() |
| + | #print("执行第 " + str(line_number) + " 行") |
| + | #print(line) |
| + | if ":slug:" in line: |
| + | target_line_number = line_number |
| + | elif ":date:" in line: |
| + | target_line = line.strip()[7:].replace(" ", "").replace("-", "").replace(":", "") |
| + | target_line = ":slug: " + str(target_line) + "\n" |
| + | |
| + | |
| + | with open(file_path, "r", ) as wfile: |
| + | alines = wfile.readlines() |
| + | target_line_number = target_line_number - 1 |
| + | #print(alines[target_line_number]) |
| + | print(alines) |
| + | alines[target_line_number] = target_line |
| + | #print(alines[target_line_number]) |
| + | print(alines) |
| + | |
| + | f = open(file_path, "w", encoding="utf-8") |
| + | f.writelines(alines) |
| + | |
| + | # 获取当前工作目录 |
| + | current_directory = os.getcwd() |
| + | |
| + | # 列出当前目录下的所有文件和文件夹 |
| + | items = os.listdir(current_directory) |
| + | |
| + | number = 0 |
| + | for item in items: |
| + | # 如果项是文件而不是文件夹,则打印它 |
| + | if os.path.isfile(os.path.join(current_directory, item)): |
| + | print(number) |
| + | number = number + 1 |
| + | print("文件名:") |
| + | print(item) |
| + | file_path = item |
| + | try: |
| + | find_slug_lines(file_path) |
| + | except Exception as e: |
| + | print(item + "不支持") |
| + | |
| + | ``` |