Blame
|
1 | # Pelican安装简要配置说明 |
||||||
| 2 | ||||||||
| 3 | ## 环境准备 |
|||||||
| 4 | ||||||||
| 5 | ### 安装miniconda |
|||||||
| 6 | ||||||||
| 7 | 下载最新版本miniconda |
|||||||
| 8 | ||||||||
|
9 | ```shell= |
||||||
|
10 | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh |
||||||
| 11 | ``` |
|||||||
| 12 | ||||||||
| 13 | ### 建立虚拟环境 |
|||||||
| 14 | ||||||||
|
15 | ```shell= |
||||||
|
16 | conda create -n pelicanenv # pelicanenv 为环境名称 |
||||||
| 17 | ``` |
|||||||
| 18 | ||||||||
| 19 | ### 激活虚拟环境 |
|||||||
| 20 | ||||||||
|
21 | ```shell |
||||||
|
22 | conda ativate pelicanenv |
||||||
| 23 | ``` |
|||||||
| 24 | ||||||||
| 25 | ## 安装软件包 |
|||||||
| 26 | ||||||||
| 27 | ### 安装pelican |
|||||||
| 28 | ||||||||
| 29 | 此处使用最新版: |
|||||||
| 30 | ||||||||
|
31 | ```shell |
||||||
|
32 | conda install conda-forge::pelican |
||||||
| 33 | ``` |
|||||||
| 34 | ||||||||
| 35 | ### 安装nginx |
|||||||
| 36 | ||||||||
|
37 | ```shell |
||||||
|
38 | apt-get install nginx |
||||||
| 39 | ``` |
|||||||
| 40 | ||||||||
| 41 | ## 创建项目 |
|||||||
| 42 | ||||||||
|
43 | ```shell |
||||||
|
44 | mkdir /xxx/xxx # 创建项目目录 |
||||||
| 45 | cd /xxx/xxx # 进入项目目录 |
|||||||
| 46 | pelican-quickstart # 生成pelican 项目 |
|||||||
| 47 | ``` |
|||||||
| 48 | ||||||||
| 49 | *安装过程过,会有很多需要你输入的配置项,如果不知道怎么填就直接忽略或者选择n,因为这些配置项在后面可以自己手动再添加的。* |
|||||||
| 50 | ||||||||
| 51 | 创建完成后生成的目录结构如下: |
|||||||
| 52 | ||||||||
|
53 | ```shell |
||||||
|
54 | . |
||||||
| 55 | ├── Makefile |
|||||||
| 56 | ├── content/ |
|||||||
| 57 | ├── develop_server.sh |
|||||||
| 58 | ├── fabfile.py |
|||||||
| 59 | ├── output/ |
|||||||
| 60 | ├── pelicanconf.py |
|||||||
| 61 | └── publishconf.py |
|||||||
| 62 | ``` |
|||||||
| 63 | ||||||||
| 64 | 所有文字,都保存在content 目录下。 |
|||||||
| 65 | ||||||||
| 66 | 建议使用markdown来写文章。 |
|||||||
| 67 | ||||||||
| 68 | ### 创建第一篇文章 |
|||||||
| 69 | ||||||||
|
70 | ```shell |
||||||
|
71 | touch xxx.md |
||||||
| 72 | ``` |
|||||||
| 73 | ||||||||
| 74 | 模板参考 |
|||||||
| 75 | ||||||||
|
76 | ```shell |
||||||
|
77 | Title: 这是我的第一篇技术博客 |
||||||
| 78 | Date: 2019-04-24 13:47:06 |
|||||||
| 79 | Category: 技术 |
|||||||
| 80 | Tags: python |
|||||||
| 81 | Slug: hello-world |
|||||||
| 82 | Summary: 这是我的第一篇技术博客,欢迎捧场 |
|||||||
| 83 | ||||||||
| 84 | ||||||||
| 85 | 这是我的第一篇技术博客,欢迎捧场,第一次写文章,还没想好怎么写,所有就随便写了一点儿。 |
|||||||
| 86 | ``` |
|||||||
| 87 | ||||||||
| 88 | ### 生成静态文件 |
|||||||
| 89 | ||||||||
|
90 | ```shell |
||||||
|
91 | pelican content |
||||||
| 92 | ``` |
|||||||
| 93 | ||||||||
| 94 | ### 启动测试服务 |
|||||||
| 95 | ||||||||
| 96 | Pelican 自己内置了一个HTTP Server,但是除非是本地开发和测试环境,否则不建议直接使用测试服务 |
|||||||
| 97 | ||||||||
|
98 | ```shell |
||||||
|
99 | pelican --listen |
||||||
| 100 | ``` |
|||||||
| 101 | ||||||||
| 102 | ### 配置nginx |
|||||||
| 103 | ||||||||
|
104 | ```shell |
||||||
|
105 | vim /etc/nginx/sites-available/default |
||||||
| 106 | ``` |
|||||||
| 107 | ||||||||
| 108 | ## 主题安装 |
|||||||
| 109 | ||||||||
| 110 | ### 下载主题 |
|||||||
| 111 | ||||||||
|
112 | ```shell |
||||||
|
113 | git clone --recursive https://github.com/getpelican/pelican-themes ~/pelican-themes |
||||||
| 114 | ``` |
|||||||
| 115 | ||||||||
| 116 | ### 安装主题 |
|||||||
| 117 | ||||||||
|
118 | ```shell |
||||||
|
119 | pelican-themes -i pelican-themes/gum |
||||||
| 120 | ``` |
|||||||
| 121 | ||||||||
| 122 | ### 启用主题 |
|||||||
| 123 | ||||||||
| 124 | 编辑 pelicanconf.py |
|||||||
| 125 | ||||||||
|
126 | ```shell |
||||||
|
127 | vim pelicanconf.py |
||||||
| 128 | ``` |
|||||||
| 129 | ||||||||
| 130 | ```python |
|||||||
| 131 | THEME = "gum" |
|||||||
| 132 | ``` |
|||||||
| 133 | ||||||||
| 134 | 重新生成静态文件 |
|||||||
| 135 | ||||||||
|
136 | ```shell |
||||||
|
137 | pelican-themes -l |
||||||
| 138 | ``` |
|||||||
| 139 | ||||||||
| 140 | 查看已经安装可用的主题 |
|||||||
| 141 | ||||||||
|
142 | ```shell |
||||||
|
143 | pelican-themes -l |
||||||
| 144 | ``` |
|||||||
| 145 | ||||||||
| 146 | ## 导入wordpress 文章 |
|||||||
| 147 | ||||||||
| 148 | 先将wordpress 文章导出为xxxx.xml |
|||||||
| 149 | ||||||||
| 150 | 然后导入pelican |
|||||||
| 151 | ||||||||
|
152 | ```shell |
||||||
|
153 | pelican-import --blogger -o ~/output ~/posts.xml |
||||||
| 154 | ``` |
|||||||
| 155 | ||||||||
| 156 | 导入后,有大量的rst 文件 |
|||||||
| 157 | ||||||||
| 158 | rst 文中slug 字段由于文章名称是中的可能出现乱码,造成前端无法直接访问 |
|||||||
| 159 | ||||||||
| 160 | 需要处理一下相关链接后,再生成相关相关静态页面 |
|||||||
| 161 | ||||||||
| 162 | 可以使用以下python 脚本: |
|||||||
| 163 | ||||||||
|
164 | ```python= |
||||||
|
165 | # -*- coding: utf-8 -*- |
||||||
| 166 | import os |
|||||||
| 167 | ||||||||
| 168 | def find_slug_lines(file_path): |
|||||||
| 169 | # 打开文件并逐行读取 |
|||||||
| 170 | with open(file_path, "r", ) as file: |
|||||||
| 171 | target_line_number = None |
|||||||
| 172 | target_line = None |
|||||||
| 173 | #alines = file.readlines() |
|||||||
| 174 | for line_number, line in enumerate(file, start=1): |
|||||||
| 175 | #alines = file.readlines() |
|||||||
| 176 | #print("执行第 " + str(line_number) + " 行") |
|||||||
| 177 | #print(line) |
|||||||
| 178 | if ":slug:" in line: |
|||||||
| 179 | target_line_number = line_number |
|||||||
| 180 | elif ":date:" in line: |
|||||||
| 181 | target_line = line.strip()[7:].replace(" ", "").replace("-", "").replace(":", "") |
|||||||
| 182 | target_line = ":slug: " + str(target_line) + "\n" |
|||||||
| 183 | ||||||||
| 184 | ||||||||
| 185 | with open(file_path, "r", ) as wfile: |
|||||||
| 186 | alines = wfile.readlines() |
|||||||
| 187 | target_line_number = target_line_number - 1 |
|||||||
| 188 | #print(alines[target_line_number]) |
|||||||
| 189 | print(alines) |
|||||||
| 190 | alines[target_line_number] = target_line |
|||||||
| 191 | #print(alines[target_line_number]) |
|||||||
| 192 | print(alines) |
|||||||
| 193 | ||||||||
| 194 | f = open(file_path, "w", encoding="utf-8") |
|||||||
| 195 | f.writelines(alines) |
|||||||
| 196 | ||||||||
| 197 | # 获取当前工作目录 |
|||||||
| 198 | current_directory = os.getcwd() |
|||||||
| 199 | ||||||||
| 200 | # 列出当前目录下的所有文件和文件夹 |
|||||||
| 201 | items = os.listdir(current_directory) |
|||||||
| 202 | ||||||||
| 203 | number = 0 |
|||||||
| 204 | for item in items: |
|||||||
| 205 | # 如果项是文件而不是文件夹,则打印它 |
|||||||
| 206 | if os.path.isfile(os.path.join(current_directory, item)): |
|||||||
| 207 | print(number) |
|||||||
| 208 | number = number + 1 |
|||||||
| 209 | print("文件名:") |
|||||||
| 210 | print(item) |
|||||||
| 211 | file_path = item |
|||||||
| 212 | try: |
|||||||
| 213 | find_slug_lines(file_path) |
|||||||
| 214 | except Exception as e: |
|||||||
| 215 | print(item + "不支持") |
|||||||
| 216 | ||||||||
| 217 | ``` |
|||||||