60

WordPress生成HTML静态化网站

 5 years ago
source link: https://www.williamlong.info/archives/5751.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

WordPress生成HTML静态化网站

2019-6-30 17:11:28 | 作者: 月光 | 分类: 网站建设 | 评论: 4 | 浏览: 5299

  十多年前,我写过一个“WordPress的静态化方法”,使用的是一个名为cos-html-cache的插件实现。

  这个插件非常简洁小巧,直接在原网站上生成首页和文章页的html文件,不过,这个插件只支持文章静态化,不支持页面、标签和分类的静态化,之后也再没有过更新。

  后来,我想到过利用WordPress插件导出全静态化网站的方法,用这个方法,对于少量文章挺方便,但文章数量一旦多了,就经常出错。

  后来,我看到有人在cos-html-cache插件的基础上又开发了一个插件,名叫Super Static Cache,我用了一下,发现其BUG较多,只有Rewrite模式是可以正常使用的,在这个模式下,可以将首页、文章页、单页、分类页、Tag页都生成静态化文件,并保存在一个名为super-static-cache的目录下,直接复制这个目录即可得到一个静态化网站。

  修复BUG的方法很简单,必须选择“Direct模式”后,将下面一行代码注释掉即可。其“Direct模式”功能实际和cos-html-cache一样,但实现了页面、标签和分类的静态化。

$rules = __('Your server type is not detected, Please visit https://www.hitoy.org/super-static-cache-for-wordperss.html for help.','super-static-cache');

  因此,一个更简单的生成静态化网站的方法来了,先在网站安装Super Static Cache,之后运行一个抓取网站的工具,这类工具很多,例如wget、sitemaps生成器之类的,把整个网站抓一遍,即可在super-static-cache的目录获取到网站的静态化Html文件。

  wgetWindows、Linux、Mac都有,用wget下载网站的命令是:

  wget -m 网站地址

WordPress生成HTML静态化网站

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK