博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用pelican创建静态博客
阅读量:6792 次
发布时间:2019-06-26

本文共 3066 字,大约阅读时间需要 10 分钟。

创建工作目录

首先使用pip安装pelican和markdown

pip install pelican markdown

然后创建目录

mkdir my_blog

接着进入目录cd my_blog,执行pelican-quickstart,当前目录内就会生成默认配置好的文件

修改配置

pelicanconf.py是博客的配置文件:

#!/usr/bin/env python# -*- coding: utf-8 -*- #from __future__ import unicode_literalsAUTHOR = u'printR'SITENAME = u"catmelo"SITEURL = 'http://www.cnblogs.com/catmelo/'PATH = 'content'TIMEZONE = 'Asia/Shanghai'DATE_FORMATS = {'zh':'%Y-%m-%d %H:%M'}DELETE_OUTPUT_DIRECTORY = FalseDEFAULT_LANG = u'zh'THEME = 'pelican-themes/pelican-bootstrap3'PLUGIN_PATHS = ["plugins", "pelican-plugins"]PLUGINS = ['tag_cloud', 'related_posts', 'pelican-toc']USE_FOLDER_AS_CATEGORY = True#DEFAULT_CATEGORY = u'文章'SITELOGO = 'images/logo.png'FAVICON = 'images/logo.png'SITELOGO_SIZE = 14ARTICLE_URL = 'posts/{category}/{slug}/'ARTICLE_SAVE_AS = 'posts/{category}/{slug}/index.html'PAGE_URL = 'pages/{slug}/'PAGE_SAVE_AS = 'pages/{slug}/index.html'MD_EXTENSIONS = ['codehilite(css_class=highlight)','extra']STATIC_PATHS = ['images', 'extra']EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}DISPLAY_ARTICLE_INFO_ON_INDEX = TrueDISPLAY_TAGS_INLINE = FalseDISPLAY_RECENT_POSTS_ON_SIDEBAR = TrueSHOW_ARTICLE_CATEGORY = TrueSHOW_DATE_MODIFIED = TrueRELATED_POSTS_TEXT = u'相关文章'FEED_ALL_ATOM = NoneCATEGORY_FEED_ATOM = NoneTRANSLATION_FEED_ATOM = NoneAUTHOR_FEED_ATOM = NoneAUTHOR_FEED_RSS = None# BlogrollLINKS = ((u'Github', 'http://github.com'),)# Social widgetSOCIAL = (('Github', 'http://github.com'),)DEFAULT_PAGINATION = 10# Uncomment following line if you want document-relative URLs when developing#RELATIVE_URLS = True#pelican_toc插件配置TOC = {    'TOC_HEADERS' : '^h[3-6]',  # What headers should be included in the generated toc                                # Expected format is a regular expression    'TOC_RUN'     : 'true'      # Default value for toc generation, if it does not evaluate                                # to 'true' no toc will be generated}

在Makefile文件里添加upload命令,方便上传到github:

...html:    $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)upload:    cd $(OUTPUTDIR) && git add -A && git commit -am "update blog" && git push origin master...

使用主题和插件

获取主题:git clone git://github.com/getpelican/pelican-themes.git

获取插件:git clone git://github.com/getpelican/pelican-plugins.git

修改pelicanconf.py文件,使主题和插件生效:

THEME = 'pelican-themes/pelican-bootstrap3' #直接指定主题目录PLUGIN_PATHS = ["plugins", "pelican-plugins"] #pelican-plugins为插件总目录PLUGINS = ['tag_cloud', 'related_posts'] #插件总目录里的插件(文件夹)名

上传到GitHub Pages

域名设置

content/extra/内添加CNAME文件,CNAME里只需写入一行域名,例如:github.com

修改pelianconf.py:

STATIC_PATHS = ['extra']EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}

git操作

cd outputgit initgit remote add origin https://github.com/your_name/your_blog.gitgit add -Agit commit -am "update blog"git pull origin mastergit push origin master

以后更新网站只需要执行:

cd my_blogmake htmlmake upload

添加logo和favicon(仅针对pelican-bootstrap3主题)

修改pelicanconf.py:

STATIC_PATHS = ['images', 'extra']SITELOGO = 'images/logo.png'FAVICON = 'images/logo.png'SITELOGO_SIZE = 14

把图标logo.png放进content/images/里即可

你可能感兴趣的文章
机器人在水下的精彩生活:探索更神秘的海洋世界
查看>>
和我一起学CSLA.NET----创建业务对象3
查看>>
Autodesk云计算-- HomeStyler在线家居设计平台
查看>>
linux rtc 接口【转】
查看>>
3. 文件系统管理
查看>>
Visual Prolog 的 Web 专家系统 (6)
查看>>
一个IT学生的personal statement
查看>>
request_mem_region 与 ioremap【转】
查看>>
项目绩效考核体系指标建设图表
查看>>
ASP.NET MVC 2.0 中文正式版发布
查看>>
【原创】开源Math.NET基础数学类库使用(17)C#计算矩阵条件数
查看>>
实例演示Android异步加载图片
查看>>
filebeat.yml(中文配置详解)
查看>>
激活另一个进程
查看>>
[]leetcode]Unique Paths II
查看>>
PHP JSON_ENCODE 不转义中文汉字的方法
查看>>
Ubuntu & GitLab CI & Docker & ASP.NET Core 2.0 自动化发布和部署(2)
查看>>
错误Name node is in safe mode的解决方法
查看>>
IntentService 与ResultReceiver
查看>>
Apache Tomcat Server Options 选项说明
查看>>