博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to publish a WordPress blog to a static GitLab Pages site
阅读量:4981 次
发布时间:2019-06-12

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

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  would be relatively easy, and the blog could then be hosted on . But trying to extract all that content and convert it to  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  (or  if you like). This would allow me to automate  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  (even though this site is actually built with Pelican).
  •  for the public URL .
  • Add a  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 . 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.

 

转载于:https://www.cnblogs.com/0xcafedaddy/p/9645432.html

你可能感兴趣的文章
免交互批量分发公钥的实现
查看>>
在Python脚本中调用Django环境
查看>>
Django Rest Framework
查看>>
orm字段类型使用
查看>>
saltstack安装使用
查看>>
centos 下 yum安装python3
查看>>
cmdb资产管理2
查看>>
Python 命令行工具 argparse 模块使用详解
查看>>
jQuery和使用oninput事件
查看>>
es学习
查看>>
anaconda使用
查看>>
python中分页使用
查看>>
爬虫学习推荐目录
查看>>
[CSS] Change the Alignment of a Single Flexed Item with 'align-self'
查看>>
[Dart] Capture and Handle Data Sequences with Streams in Dart
查看>>
[Dart] splitMapJoin
查看>>
[Angular] Show a Loading Indicator for Lazy Routes in Angular
查看>>
[HTML5] Lazyload below the fold images and iframes with native browser lazy-loading
查看>>
[HTML5] Add Semantic Styling to the Current Page of a Navigation Item with aria-current
查看>>
[React Native] Up & Running with React Native & TypeScript
查看>>