博客文章头图

使用Cloudflare托管Mkdocs文档

702 字
2 分钟
Blog
Cloudflare

如果是 Jekyll 站点 GitHub 也支持直接自动部署,当然其他一些静态站点 Github 也可以通过 Action 完成自动部署,但是这里选择 Cloudflare 是因为它对建站更友好,尤其是自定义域和保护源码。

1. 创建Pages

控制台主页面 Workers 和 Pages -> 创建应用程序 -> Pages

img

img

2. 部署源码

如果是简单的几个Html和js/css 文件,直接上传即可;

这里使用 连接到Git ,使用Github 或 GitLab上的仓库,如果没有绑定Github账号先绑定;

这里比Github友好的地方就行可以选择私有仓库,这样别人就不能直接copy你的源码了

img

3. 选择部署

当前网站使用的是 mkdocs-material 他是基于 Mkdocs的 所以选择 Mkdocs

因为当前(2023年10月10日) cloudflare 支持了2.0 版本构建系统,所以设置环境变量为经典版本 python 3.8 ,原则上支持到python 3.11,之前的版本不支持高版本Python;这也是我最近发现的,因为发现git push 没问题但网站内容没更新,一看cloudflare 部署失败了,所以顺便选择2.0 构建系统了

PYTHON_VERSION = 3.8

img

保存并部署,继续选择继续处理项目即可

img

4. 部署完成

img

其他注意事项

关于 Jekyll 部署,有一点需要注意的是,在国内的用户或许会使用 https://gems.ruby-china.com/ 源,但是Cloudflare 对这个源部署Jekyll不太友好,拉取依赖包特别慢甚至十分钟以上,所以替换成 ruby 官方源

https://gems.ruby-china.com/ # 国内源
https://rubygems.org/ # 官方源

如:

source "https://rubygems.org/"  
gem "github-pages", group: :jekyll_plugins  

group :jekyll_plugins do  
  gem 'webrick'  
end

当前的博客的配置文件

mkdocs.yml

site_name: COCO鸭的笔记  

theme:  
  name: material  
  custom_dir: overrides  
  logo: themes/assets/logo.png  
  favicon: themes/assets/logo.png  
  features:  
    - content.code.copy  
    - header.autohide  
    - navigation.instant # https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/?h=nav#instant-loading  
    - navigation.tabs # 导航先选卡 https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/?h=nav#navigation-tabs  
markdown_extensions:  
  - pymdownx.highlight:  
      anchor_linenums: true  
      line_spans: __span  
      pygments_lang_class: true  
  - pymdownx.inlinehilite  
  - pymdownx.snippets  
  - pymdownx.superfences  
  - attr_list  
  - md_in_html  

nav:  
  - Home:  
      - index.md  
  - ...| Note/**  
  - About:  
      - about.md  
# ... 表示自动生成导航,由mkdocs-awesome-pages-plugin 支持  

extra_css:  
  - themes/stylesheets/extra.css  

extra:  
  social: # 社交链接  
    - icon: fontawesome/brands/github  
      link: https://github.com/xx025  
      name: GitHub  


plugins:  
  - search  
  - awesome-pages  
  - git-revision-date-localized:  
      enable_creation_date: true  
#  - blog:  
#      blog_dir: Blog  

copyright: Copyright © 2023 coco鸭 

requirements.txt

mkdocs-material  
mkdocs-awesome-pages-plugin  
mkdocs-git-revision-date-localized-plugin  
本站内容采用 CC BY-NC-SA 4.0 许可,请注明出处;商业转载请联系作者授权。