1
0
mirror of https://github.com/trambarhq/relaks-wordpress-example.git synced 2025-09-03 05:02:34 +02:00

Fixed cache purge (issue #50).

Fixed permalinks with date (issue #49).
This commit is contained in:
Chung Leong
2019-02-03 14:20:43 +01:00
parent 7b381cbd42
commit d94aca4ae4
4 changed files with 24 additions and 38 deletions

View File

@@ -128,14 +128,14 @@ async function handlePurgeRequest(req, res) {
// verify that require is coming from WordPress
let remoteIP = req.connection.remoteAddress;
res.end();
let wordpressIP = await dnsCache.lookupAsync(WORDPRESS_HOST.replace(/^https?:\/\//));
let wordpressIP = await dnsCache.lookupAsync(WORDPRESS_HOST.replace(/^https?:\/\//, ''));
if (remoteIP !== `::ffff:${wordpressIP}`) {
return;
}
let url = req.url;
let method = req.headers['x-purge-method'];
if (method === 'regex' && url === '.*') {
if (method === 'regex' && url === '/.*') {
pageDependencies = {};
await NginxCache.purge(/.*/);
} else if (method === 'default') {

View File

@@ -84,6 +84,7 @@ class Route {
let matchLink = (obj) => {
return _.trimEnd(obj.link, '/') === link;
};
let slugs = _.filter(_.split(path, '/'));
// see if it's a search
let search = query.s;
@@ -97,14 +98,23 @@ class Route {
}
// see if it's pointing to an archive
let date = findDate(path);
if (date) {
if (slugs[0] === 'date' && /^\d+$/.test(slugs[1]) && /^\d+$/.test(slugs[2]) && slugs.length == 3) {
let date = {
year: parseInt(slugs[1]),
month: parseInt(slugs[2]),
};
return { pageType: 'archive', date, siteURL };
} else if (/^\d+$/.test(slugs[0]) && /^\d+$/.test(slugs[1]) && slugs.length == 2) {
let date = {
year: parseInt(slugs[0]),
month: parseInt(slugs[1]),
};
return { pageType: 'archive', date, siteURL };
}
// see if it's pointing to a post by ID
let postID = findPostID(path);
if (postID) {
if (slugs[0] === 'archives' && /^\d+$/.test(slugs[1])) {
let postID = parseInt(slugs[1]);
let post = await wp.fetchPost(postID);
if (post) {
return { pageType: 'post', postSlug: post.slug, siteURL };
@@ -127,16 +137,14 @@ class Route {
// see if it's pointing to a popular tag
let topTags = await wp.fetchTopTags();
let tag = _.find(topTags, matchLink);
if (tag) {
return { pageType: 'tag', tagSlug: tag.slug, siteURL };
let topTag = _.find(topTags, matchLink);
if (topTag) {
return { pageType: 'tag', tagSlug: topTag.slug, siteURL };
}
// see if it's pointing to a not-so popular tag
let slugs = _.filter(_.split(path, '/'));
if (slugs.length >= 2 && _.includes(slugs, 'tag')) {
let tagSlug = _.last(slugs);
let tag = await wp.fetchTag(tagSlug);
if (slugs[0] === 'tag' && slugs.length === 2) {
let tag = await wp.fetchTag(slugs[1]);
if (tag) {
return { pageType: 'tag', tagSlug: tag.slug, siteURL };
}
@@ -155,7 +163,7 @@ class Route {
// see if it's pointing to a tag when no prefix is used
let tagSlug = _.last(slugs);
tag = await wp.fetchTag(tagSlug);
let tag = await wp.fetchTag(tagSlug);
if (tag) {
return { pageType: 'tag', tagSlug: tag.slug, siteURL };
}
@@ -228,28 +236,6 @@ class Route {
}
}
function findDate(path) {
if (_.startsWith(path, '/date/')) {
path = path.substr(5);
}
let m = /^\/(\d{4})\/(\d+)\/?/.exec(path);
if (m) {
return {
year: parseInt(m[1]),
month: parseInt(m[2]),
};
}
}
function findPostID(path) {
if (_.startsWith(path, '/archives/')) {
let id = parseInt(path.substr(10));
if (id === id) {
return id;
}
}
}
let routes = {
'page': { path: '*' },
};

View File

@@ -328,7 +328,7 @@ A {
}
.comments {
font-size: 0.9em;
font-size: 0.9rem;
padding-left: 1.5em;
.commenter {

View File

@@ -12,7 +12,7 @@ var ExtractTextPlugin = require("extract-text-webpack-plugin");
var EVENT = process.env.npm_lifecycle_event;
var BUILD = (EVENT === 'build') ? 'production' : 'development';
var IS_DEV_SERVER = process.argv.find((arg) => { return arg.includes('webpack-dev-server') });
var DEV_DATA_HOST = (IS_DEV_SERVER) ? 'http://192.168.0.56:8000' : undefined;
var DEV_DATA_HOST = (IS_DEV_SERVER) ? 'http://localhost:8000' : undefined;
var CORDOVA_DATA_HOST = process.env.CORDOVA_DATA_HOST;
var BASE_PATH = '/';