How to publish a WordPress blog to a static GitLab Pages site
https://opensource.com/article/18/8/publish-wordpress-static-gitlab-pages-site
A long time ago, I set up a WordPress blog for a family member. There are lots of options these days, but back then there were few decent choices if you needed a web-based CMS with a WYSIWYG editor. An unfortunate side effect of things working well is that the blog has generated a lot of content over time. That means I was also regularly updating WordPress to protect against the exploits that are constantly popping up.
So I decided to convince the family member that switching to Hugo would be relatively easy, and the blog could then be hosted on GitLab. But trying to extract all that content and convert it to Markdown turned into a huge hassle. There were automated scripts that got me 95% there, but nothing worked perfectly. Manually updating all the posts was not something I wanted to do, so eventually, I gave up trying to move the blog.
Recently, I started thinking about this again and realized there was a solution I hadn't considered: I could continue maintaining the WordPress server but set it up to publish a static mirror and serve that with GitLab Pages (or GitHub Pages if you like). This would allow me to automate Let's Encrypt certificate renewals as well as eliminate the security concerns associated with hosting a WordPress site. This would, however, mean comments would stop working, but that feels like a minor loss in this case because the blog did not garner many comments.
Here's the solution I came up with, which so far seems to be working well:
- Host WordPress site at URL that is not linked to or from anywhere else to reduce the odds of it being exploited. In this example, we'll use http://private.localconspiracy.com (even though this site is actually built with Pelican).
- Set up hosting on GitLab Pages for the public URL https://www.localconspiracy.com.
- Add a cron job that determines when the last-built date differs between the two URLs; if the build dates differ, mirror the WordPress version.
- After mirroring with
wget, update all links from "private" version to "public" version. - Do a
git pushto publish the new content.
These are the two scripts I use:
check-diff.sh (called by cron every 15 minutes)
ORIGINDATE="$(curl -v --silent http://private.localconspiracy.com/feed/ 2>&1|grep lastBuildDate)"
PUBDATE="$(curl -v --silent https://www.localconspiracy.com/feed/ 2>&1|grep lastBuildDate)"
if [ "$ORIGINDATE" != "$PUBDATE" ]
then
/home/doc/repos/localconspiracy/mirror.sh
fi
mirror.sh:
cd /home/doc/repos/localconspiracy
wget \
--mirror \
--convert-links \
--adjust-extension \
--page-requisites \
--retry-connrefused \
--exclude-directories=comments \
--execute robots=off \
http://private.localconspiracy.com
git rm -rf public/*
mv private.localconspiracy.com/* public/.
rmdir private.localconspiracy.com
find ./public/ -type f -exec sed -i -e 's|http://private.localconspiracy|https://www.localconspiracy|g' {} \;
find ./public/ -type f -exec sed -i -e 's|http://www.localconspiracy|https://www.localconspiracy|g' {} \;
git add public/*
git commit -m "new snapshot"
git push origin master
That's it! Now, when the blog is changed, within 15 minutes the site is mirrored to a static version and pushed up to the repo where it will be reflected in GitLab pages.
This concept could be extended a little further if you wanted to run WordPress locally. In that case, you would not need a server to host your WordPress blog; you could just run it on your local machine. In that scenario, there's no chance of your blog getting exploited. As long as you can run wget against it locally, you could use the approach outlined above to have a WordPress site hosted on GitLab Pages.
How to publish a WordPress blog to a static GitLab Pages site的更多相关文章
- Windows下搭建Wordpress博客网站
一:安装wamp Windows下的Apache+Mysql/MariaDB+Perl/PHP/Python,一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使 ...
- SEO技巧之WordPress篇幅
随着搜索引擎大兴, 排列在前的网站引入大量流量. 无论是搜索页面的广告还是查出来的结果, 与搜索者的目标匹配度都比较高 (如果搜索引擎足够智能), 所以通过搜索引擎而来的访客很可能会从网站上得到他想要 ...
- 2015年免费的25款 WordPress 网站模板
2015年 WordPress 插件和主题的数量继续在增长.这一年,我们可以期待WP主题引入一些新的技术,从背景,自适应响应式图像到从背景图片中提取主色. 本文包含25款最近发布的 WordPress ...
- WordPress 主题开发 - (四) 创建WordPress的主题HTML结构 待翻译
Now we're starting to get into the real meat of WordPress Theme development: coding the HTML structu ...
- WordPress 主题开发 - (八) Head模板 待翻译
THE WORDPRESS THEME HEADER TEMPLATE Now we get into the nitty-gritty: building up your header.php an ...
- [Linux] Ubuntu Server 12.04 LTS 平台上搭建WordPress(Nginx+MySQL+PHP) Part IV
接下来我们去下载 WorePress 用最新的 3.7.1 下载地址是:http://cn.wordpress.org/wordpress-3.7.1-zh_CN.zip 我们先建立一个文件夹 /va ...
- 关闭WordPress自动加载的Open Sans字体-WP访问过慢原因
序言 wordpress大概从wp-3.8开始会自动加载Open Sans字体,并引用Google上面的CSS样式.而最近谷歌经常打不开,导致网站访问速度过慢,严重的会拖慢几十秒.Open Sans字 ...
- (转)关闭WordPress自动加载的Open Sans字体,总是连接googleapi.com,导致打开wordpress很慢
转自http://www.xuanfengge.com/turn-off-automatic-loading-wordpress-open-sans-fonts.html 一.'在网上搜了一番,有四种 ...
- windows下安装wamp和wordpress
安装wamp WAMP是一个windows上的php开发集成环境,一键安装php,apache和mysql,非常方便. 双击wampserver2.2exxxxxxxxxx.exe文件进行安装,安装过 ...
随机推荐
- 前端获得session信息方式对比,优化
在开发中,页面 js 经常会遇到需要 当前登录用户信息(菜单权限,用户基本信息,配置信息) 的地方,一般情况我们可能对这些信息获取方式不是太在意,但是现在的前端通过webpack打包,即使做了代码分割 ...
- nodejs pm2使用
参考地址:http://www.jianshu.com/p/43525232b03b 参考地址:http://blog.csdn.net/leo_perfect/article/details/536 ...
- Java集合之ArrayList与LinkList
注:示例基于JDK1.8版本 参考资料:Java知音公众号 本文超长,也是搬运的干货,希望小伙伴耐心看完. Collection集合体系 List.Set.Map是集合体系的三个接口. 其中List和 ...
- Protocol Buffers 在前端项目中的使用
前言: 公司后端使用的是go语言,想尝试用pb和前端进行交互,于是便有了这一次尝试,共计花了一星期时间,网上能查到的文档几乎都看了一遍,但大多都是教在node环境下如何使用,普通的js环境下很多讲述的 ...
- JavaWeb中常见的乱码处理(亲测)
常见编码方式: ISO-8859-1 西欧码 GB2312 简体中文码 GBK 大五码 UTF-8 全球码(推荐) 1.页面(HTML,JSP,Servlet) <%@ page lan ...
- 关于matplotlib,你要的饼图在这里
Table of Contents 1 官方Demo 2 将实际数据应用于官方Demo 3 一些改善措施 3.1 重新设置字体大小 3.2 设置显示颜色,Method 1: 3.3 设置显 ...
- Outlook Font
- angularjs学习笔记3-directive中scope的绑定修饰符
在angularjs中,一个directive返回一个对象,对象存在很多属性,并且可以在directive中自定义自己的scope,而使用自己的scope是为了防止一个directive被使用在多个地 ...
- 最长上升子序列:2016 Pacific Northwest Region Programming Contest—Division 2 Problem M
Description A string of lowercase letters is calledalphabeticalif deleting zero or more of its lette ...
- HDU 4388 Stone Game II 博弈论 找规律
http://acm.hdu.edu.cn/showproblem.php?pid=4388 http://blog.csdn.net/y1196645376/article/details/5214 ...