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 push to publish the new content.

These are the two scripts I use:

 

check-diff.sh (called by cron every 15 minutes)

#!/bin/bash

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:

#!/bin/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的更多相关文章

  1. Windows下搭建Wordpress博客网站

    一:安装wamp Windows下的Apache+Mysql/MariaDB+Perl/PHP/Python,一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使 ...

  2. SEO技巧之WordPress篇幅

    随着搜索引擎大兴, 排列在前的网站引入大量流量. 无论是搜索页面的广告还是查出来的结果, 与搜索者的目标匹配度都比较高 (如果搜索引擎足够智能), 所以通过搜索引擎而来的访客很可能会从网站上得到他想要 ...

  3. 2015年免费的25款 WordPress 网站模板

    2015年 WordPress 插件和主题的数量继续在增长.这一年,我们可以期待WP主题引入一些新的技术,从背景,自适应响应式图像到从背景图片中提取主色. 本文包含25款最近发布的 WordPress ...

  4. WordPress 主题开发 - (四) 创建WordPress的主题HTML结构 待翻译

    Now we're starting to get into the real meat of WordPress Theme development: coding the HTML structu ...

  5. WordPress 主题开发 - (八) Head模板 待翻译

    THE WORDPRESS THEME HEADER TEMPLATE Now we get into the nitty-gritty: building up your header.php an ...

  6. [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 ...

  7. 关闭WordPress自动加载的Open Sans字体-WP访问过慢原因

    序言 wordpress大概从wp-3.8开始会自动加载Open Sans字体,并引用Google上面的CSS样式.而最近谷歌经常打不开,导致网站访问速度过慢,严重的会拖慢几十秒.Open Sans字 ...

  8. (转)关闭WordPress自动加载的Open Sans字体,总是连接googleapi.com,导致打开wordpress很慢

    转自http://www.xuanfengge.com/turn-off-automatic-loading-wordpress-open-sans-fonts.html 一.'在网上搜了一番,有四种 ...

  9. windows下安装wamp和wordpress

    安装wamp WAMP是一个windows上的php开发集成环境,一键安装php,apache和mysql,非常方便. 双击wampserver2.2exxxxxxxxxx.exe文件进行安装,安装过 ...

随机推荐

  1. git: Your branch and 'origin/master' have diverged

    git: Your branch and 'origin/master' have diverged - how to throw away local commits? - Stack Overfl ...

  2. oracle 导入dmp文件

    /*第1步:创建临时表空间  */ create temporary tablespace webdata_temp tempfile 'D:\oracle\product\10.2.0\oradat ...

  3. sonarQube安装及本机扫描C#项目

    因项目需要,需要使用sonarQube对代码进行扫描并查看,因对sonarQube不熟悉,所以先在本机搭建测试环境. 参考了张老师的博客:http://www.cnblogs.com/danzhang ...

  4. es2015(es6)学习总结

    1.三种声明方式 var:它是variable的简写,可以理解成变量的意思. let:它在英文中是“让”的意思,也可以理解为一种声明的意思. const:它在英文中也是常量的意思,在ES6也是用来声明 ...

  5. HDU 6463.超级无敌简单题-卡边界的暴力 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    超级无敌简单题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. Java工具类-验证码工具

    1.工具类,生成随机验证码字符串 import java.util.Arrays; /** * 工具类,生成随机验证码字符串 * * @version 1.0 * @author * */ publi ...

  7. python笔记四:面向对象

    1.类 class Student(object): def __init__(self, name, score): self.name = name self.score = score 1)__ ...

  8. 阿里云轻量级学生机搭建FTP最新教程

    碰了几次壁,我整理一下分析自己在阿里云上成功安装FTP的教程. 1.使用root用户进入云服务器. 2.rpm  -qa|grep vsftpd 查看是否安装了ftp,一般阿里云服务器你以前没安装过, ...

  9. Xamarin.Forms教程下载安装Windows版的Xamarin开发工具

    Xamarin.Forms教程下载安装Windows版的Xamarin开发工具 下载安装Windows版的Xamarin开发工具 本节将讲解如何下载并安装Windows版的Xamarin开发工具. 下 ...

  10. 【BZOJ 2288】 2288: 【POJ Challenge】生日礼物 (贪心+优先队列+双向链表)

    2288: [POJ Challenge]生日礼物 Description ftiasch 18岁生日的时候,lqp18_31给她看了一个神奇的序列 A1, A2, ..., AN. 她被允许选择不超 ...